home *** CD-ROM | disk | FTP | other *** search
/ LSD Docs / LSD Docs.iso / FILEZ / lsd39.dms / lsd39.adf / arexx.doc.pp / arexx.doc
Text File  |  1978-01-15  |  292KB  |  6,600 lines

  1.  
  2.               TABLE OF CONTENTS
  3.  
  4.             AREXX USER'S REFERENCE MANUAL
  5.  
  6. INTRODUCTION....................................................1
  7.  1. Organization of this Document...............................1
  8.     1 Using this Manual.........................................2
  9.     2 Typographic Conventions...................................2
  10.  2. Future Directions...........................................2
  11. CHAPTER 1. WHAT IS AREXX?.......................................3
  12.  1. Language Features...........................................3
  13.  2. ARexx on the Amiga..........................................4
  14.  3. Further Information.........................................4
  15. CHAPTER 2. GETTING ACQUAINTED...................................5
  16.  1. Installing ARexx............................................5
  17.     1 ARexx and Workbench.......................................5
  18.     2 Installation..............................................5
  19.     3 Starting the Resident Process.............................6
  20.     4 Naming Conventions........................................6
  21.     5 The REXX: Directory.......................................6
  22.  2. Program Examples............................................7
  23. CHAPTER 3. ELEMENTS OF THE LANGUAGE............................11
  24.  1. Format.....................................................11
  25.  2. Tokens.....................................................11
  26.     1 Comment Tokens...........................................11
  27.     2 Symbol Tokens............................................11
  28.     3 String Tokens............................................12
  29.     4 Operators................................................12
  30.     5 Special Character Tokens.................................13
  31.  3. Clauses....................................................14
  32.     1 Null Clauses.............................................14
  33.     2 Label Clauses............................................14
  34.     3 Assignment Clauses.......................................14
  35.     4 Instruction Clauses......................................15
  36.     5 Command Clauses..........................................15
  37.     6 Clause Classification....................................15
  38.  4. Expressions................................................16
  39.     1 Symbol Resolution........................................16
  40.     2 Order of Evaluation......................................16
  41.  5. Numbers and Numeric Precision..............................17
  42.     1 Boolean Values...........................................17
  43.     2 Numeric Precision........................................17
  44.  6. Operators..................................................18
  45.     1 Arithmetic Operators.....................................18
  46.     2 Concatenation Operators..................................20
  47.     3 Comparison Operators.....................................20
  48.     4 Logical (Boolean) Operators..............................21
  49.  7. Stems and Compound Symbols.................................21
  50.  
  51.                 i
  52.  
  53. CHAPTER 3. ELEMENTS OF THE LANGUAGE (CONT).....................11
  54.  8. The Execution Environment..................................22
  55.     1 The External Environment.................................22
  56.     2 The Internal Environment.................................22
  57.     3 Input and Output.........................................23
  58.     4 Resource Tracking........................................24
  59. CHAPTER 4. INSTRUCTIONS........................................25
  60.  1. ADDRESS....................................................25
  61.  2. ARG........................................................25
  62.  3. BREAK......................................................26
  63.  4. CALL.......................................................26
  64.  5. DO.........................................................27
  65.  6. DROP.......................................................28
  66.  7. ECHO.......................................................28
  67.  8. ELSE.......................................................28
  68.  9. END........................................................29
  69.  10. EXIT......................................................29
  70.  11. IF........................................................29
  71.  12. INTERPRET.................................................30
  72.  13. ITERATE...................................................30
  73.  14. LEAVE.....................................................31
  74.  15. NOP.......................................................31
  75.  16. NUMERIC...................................................31
  76.  17. OPTIONS...................................................32
  77.  18. OTHERWISE.................................................32
  78.  19. PARSE.....................................................33
  79.      1 Input Sources...........................................33
  80.      2 Templates...............................................34
  81.  20. PROCEDURE.................................................35
  82.  21. PULL......................................................35
  83.  22. PUSH......................................................36
  84.  23. QUEUE.....................................................37
  85.  24. RETURN....................................................37
  86.  25. SAY.......................................................38
  87.  26. SELECT....................................................38
  88.  27. SHELL.....................................................38
  89.  28. SIGNAL....................................................38
  90.  29. THEN......................................................39
  91.  30. TRACE.....................................................40
  92.  31. UPPER.....................................................40
  93.  32. WHEN......................................................41
  94. CHAPTER 5. COMMANDS............................................43
  95.  1. Command Clauses............................................43
  96.  2. The Host Address...........................................44
  97.  3. The Command Interface......................................44
  98.  4. Using Commands in Macro Programs...........................45
  99.  5. Using ARexx with Command Shells............................45
  100.  6. Command Inhibition.........................................46
  101.  
  102.                 ii
  103.  
  104. CHAPTER 6. FUNCTIONS...........................................47
  105.  1. Syntax and Search Order....................................47
  106.     1 Search Order.............................................47
  107.     2 Internal Functions.......................................48
  108.     3 Built-In Functions.......................................49
  109.     4 External Function Libraries..............................49
  110.     5 Function Hosts...........................................50
  111.  2. The Built-In Function Library..............................50
  112.     1 ABBREV().................................................51
  113.     2 ABS()....................................................51
  114.     3 ADDLIB().................................................51
  115.     4 ADDRESS()................................................51
  116.     5 ARG()....................................................52
  117.     6 B2C()....................................................52
  118.     7 BITAND().................................................52
  119.     8 BITCHG().................................................52
  120.     9 BITCLR().................................................53
  121.     10 BITCOMP()...............................................53
  122.     11 BITOR().................................................53
  123.     12 BITSET()................................................53
  124.     13 BITTST()................................................53
  125.     14 BITXOR()................................................54
  126.     15 C2B()...................................................54
  127.     16 C2D()...................................................54
  128.     17 C2X()...................................................54
  129.     18 CENTER() OR CENTRE()....................................55
  130.     19 CLOSE().................................................55
  131.     20 COMPRESS()..............................................55
  132.     21 COMPARE()...............................................55
  133.     22 COPIES()................................................55
  134.     23 D2C()...................................................56
  135.     24 DATATYPE()..............................................56
  136.     25 DELSTR()................................................56
  137.     26 DELWORD()...............................................57
  138.     27 EOF()...................................................57
  139.     28 ERRORTEXT().............................................57
  140.     29 EXISTS()................................................57
  141.     30 EXPORT()................................................57
  142.     31 FREESPACE().............................................58
  143.     32 GETCLIP()...............................................58
  144.     33 GETSPACE()..............................................58
  145.     34 HASH()..................................................58
  146.     35 IMPORT()................................................59
  147.     36 INDEX().................................................59
  148.     37 INSERT()................................................59
  149.     38 LASTPOS()...............................................59
  150.     39 LEFT()..................................................60
  151.     40 LENGTH()................................................60
  152.  
  153.                 iii
  154.  
  155.     41 MAX()...................................................60
  156.     42 MIN()...................................................60
  157.     43 OPEN()..................................................60
  158.     44 OVERLAY()...............................................61
  159.     45 POS()...................................................61
  160.     46 PRAGMA()................................................61
  161.     47 RANDOM()................................................62
  162.     48 RANDU().................................................62
  163.     49 READCH()................................................62
  164.     50 READLN()................................................63
  165.     51 REMLIB()................................................63
  166.     52 REVERSE()...............................................63
  167.     53 RIGHT().................................................63
  168.     54 SEEK()..................................................63
  169.     55 SETCLIP()...............................................64
  170.     56 SHOW()..................................................64
  171.     57 SIGN()..................................................64
  172.     58 SPACE().................................................64
  173.     59 STORAGE()...............................................65
  174.     60 STRIP().................................................65
  175.     61 SUBSTR()................................................65
  176.     62 SUBWORD()...............................................66
  177.     63 SYMBOL()................................................66
  178.     64 TIME()..................................................66
  179.     65 TRACE().................................................67
  180.     66 TRANSLATE().............................................67
  181.     67 TRIM()..................................................67
  182.     68 UPPER().................................................67
  183.     69 VALUE().................................................68
  184.     70 VERIFY()................................................68
  185.     71 WORD()..................................................68
  186.     72 WORDINDEX().............................................68
  187.     73 WORDLENGTH()............................................68
  188.     74 WORDS().................................................69
  189.     75 WRITECH()...............................................69
  190.     76 WRITELN()...............................................69
  191.     77 X2C()...................................................69
  192.     78 XRANGE()................................................69
  193. CHAPTER 7. TRACING AND INTERRUPTS..............................71
  194.  1. Tracing Options............................................71
  195.  2. Display Formatting.........................................72
  196.     1 Tracing Output...........................................72
  197.     2 Command Inhibition.......................................73
  198.  3. Interactive Tracing........................................73
  199.     1 Error Processing.........................................74
  200.     2 The External Tracing Flag................................74
  201.  4. Interrupts.................................................74
  202.  
  203.                 iv
  204.  
  205. CHAPTER I. PARSING AND TEMPLATES...............................77
  206.  1. Template Structure.........................................77
  207.     1 Template Objects.........................................78
  208.     2 The Scanning Process.....................................78
  209.  2. Templates in Action........................................79
  210.     1 Parsing by Tokenization..................................79
  211.     2 Pattern Parsing..........................................80
  212.     3 Positional Markers.......................................80
  213.     4 Multiple Templates.......................................80
  214. CHAPTER 9. THE RESIDENT PROCESS................................83
  215.  1. Command Utilities..........................................83
  216.     1 HI.......................................................83
  217.     2 RX.......................................................84
  218.     3 RXSET....................................................84
  219.     4 RXC......................................................84
  220.     5 TCC......................................................84
  221.     6 TCO......................................................84
  222.     7 TE.......................................................84
  223.     8 TS.......................................................84
  224.  2. Resource Management........................................85
  225.     1 The Global Tracing Console...............................85
  226.     2 The Library List.........................................85
  227.     3 The Clip List............................................86
  228. CHAPTER 10. INTERFACING TO AREXX...............................89
  229.  1. Basic Structers............................................90
  230.  2. Designing a Command Interface..............................91
  231.     1 Receiving Command Messages...............................92
  232.     2 Result Fields............................................92
  233.     3 Multiple Host Processes..................................92
  234.  3. Invoking ARexx Programs....................................93
  235.     1 Message Packets..........................................93
  236.     2 Command Invocations......................................94
  237.     3 Function Invocations.....................................95
  238.     4 Search Order.............................................95
  239.     5 Extension Fields.........................................96
  240.     6 Interpreting the Result Fields...........................97
  241.  4. Communicating with the Resident Process....................97
  242.     1 Command (Action) Codes...................................97
  243.     2 Modifier Flags...........................................99
  244.     3 Result Fields...........................................100
  245.  5. External Function Libraries...............................100
  246.     1 Design Considerations...................................100
  247.     2 Calling Convention......................................101
  248.     3 Parameter Conversion....................................101
  249.     4 Returned Values.........................................101
  250.  6. Direct Manipulation of Data Structures....................102
  251.  
  252.                 v
  253.  
  254. APPENDIX A. ERROR MESSAGES....................................103
  255. APPENDIX B. LIMITS AND COMPATIBILITY..........................109
  256.  1 Limits.....................................................109
  257.  2 Compatibility..............................................109
  258. APPENDIX C. THE AREXX SYSTEMS LIBRARY.........................111
  259.  1 Functional Groups..........................................111
  260.  2 Library Functions..........................................113
  261. APPENDIX D. THE AREXX SUPPORT LIBRARY.........................127
  262.    1 ALLOCMEM()...............................................127
  263.    2 CLOSEPORT()..............................................127
  264.    3 FREEMEM()................................................128
  265.    4 GETARG().................................................128
  266.    5 GETPKT().................................................128
  267.    6 OPENPORT()...............................................128
  268.    7 REPLY()..................................................129
  269.    8 SHOWDIR()................................................129
  270.    9 SHOWLIST()...............................................129
  271.    10 STATEF()................................................130
  272.    11 WAITPKT()...............................................130
  273. APPENDIX E. DISTRIBUTION FILES................................131
  274.  1 Directories................................................131
  275.    1 The :C Directory.........................................131
  276.    2 The :INCLUDE Directory...................................131
  277.    3 The :LIBS Directory......................................132
  278.    4 The :REXX Directory......................................132
  279.    5 The :TOOLS Directory.....................................132
  280.    6 Miscellaneous Files......................................132
  281.  2 Listings of Header Files...................................133
  282.    1 storage.h................................................133
  283.    2 rxslib.h.................................................139
  284.    3 rexxio.h.................................................142
  285.    4 errors.h.................................................144
  286. GLOSSARY......................................................147
  287. INDEX.........................................................151
  288.  
  289.                 vi
  290.  
  291.                INTRODUCTION
  292.  
  293. Welcome to ARexx,an implementation of the REXX language for the Amiga computer.
  294. ARexx is a powerful programming took,but one which by virtue of its clean
  295. syntax and sparse vocabulary is also easy to learn and easy to use.
  296.  
  297. 1 ORGANIZATION OF THIS DOCUMENT
  298.  
  299. This document will attempt to fill the roles of User's Manual,Language
  300. Reference,and Programmer's Guide. The chapters that follow have been organized
  301. to provide a gently introduction to the language.
  302.  
  303. Chapter 1,What is ARexx?,gives an overview of the ARexx language and its
  304. implementation of the Amiga.
  305.  
  306. Chapter 2,Getting Acquainted,tells how to install ARexx on your Amiga and
  307. presents several example programs to illustrate the features of the language.
  308.  
  309. Chapter 3,Elements of the Language,introduces the language structure and
  310. syntax.
  311.  
  312. Chapter 4,Instructions,describes the action statements of ARexx.
  313.  
  314. Chapter 5,Commands,describes the program statements used to communicate with
  315. external programs.
  316.  
  317. Chapter 6,Functions,explains how functions are called and documents the Built-
  318. In Function library.
  319.  
  320. Chapter 7,Tracing and Interrupts,describes the source level debugging features
  321. useful for developing and testing programs.
  322.  
  323. Chapter 8,Parsing and Templates,describes the instructions used to extract
  324. words or fields from strings.
  325.  
  326. Chapter 9,The Resident Process,describes the capabilities of the global
  327. communications and resources manager.
  328.  
  329. Chapter 10,Interfacing to ARexx,describes how to design and implement an
  330. interface between ARexx and an external program.
  331.  
  332. Appendix A,Error Messages,lists the error messages issued by the interpreter.
  333.  
  334. Appendix B,Limits and Compatibility,discusses the compatibility of ARexx with
  335. the language standard.
  336.  
  337. Appendix C,The ARexx Systems Library,documents the functions of ARexx systems
  338. library.
  339.  
  340. Appendix D,The Support Library,documents the library of Amiga specific
  341. functions.
  342.  
  343. Appendix E,Distribution Files,lists the files on the distribution disk.
  344.  
  345. Finally,a Glossary and an Index are provided.
  346.  
  347.                 1
  348.  
  349. USING THIS MANUAL
  350.  
  351. If you are new to the REXX language,or perhaps to programming itself,you should
  352. review chapters 1 through 4 and then play with ARexx by running some of the
  353. sample programs given in chapter 2. Further examples are available in the :rexx
  354. directory of the distribution disk.
  355.  
  356. If you are already familiar with REXX you may wish to skip directly to chapter
  357. 5,which begins to present some of the system-dependent features of this
  358. implementation. A summary of the compatibility of ARexx with the language
  359. definition is contained in Appendix B.
  360.  
  361. TYPOGRAPHIC CONVENTIONS
  362.  
  363. Describing a language is sometimes difficult because of the multiple and
  364. changing contexts involved. To help clarify the presentation here,a simply
  365. typographic convention has been adopted throughout the document. All of the
  366. terms and words specific to the REXX language,as well as the program examples
  367. and computer input and output,have been set in typewriter font like this. This
  368. should help to distinguish the language keywords and examples from the
  369. surrounding text.
  370.  
  371. 2 FUTURE DIRECTIONS
  372.  
  373. ARexx,like most software products,will probably envolve somewhat over the next
  374. few years as new features are added,old bugs are removed,and market imperatives
  375. become more apparant. While the core language will probably undergo few
  376. modifications,many capabilities will be added to the function libraries
  377. supported by ARexx. Your comments and suggestions for improvements to ARexx are
  378. most welcome.
  379.  
  380. The author sincerely hopes that other software developers will consider using
  381. ARexx with their products. The advantages of having a rich variety of software
  382. products sharing a common user interface and a common procedural interface
  383. cannot be overstated. This is the underlying promise of the Amiga's
  384. multitasking capability,and that which most sets it apart from other
  385. inexpensive computers.
  386.  
  387. Example Programs. One of the best ways to learn a computer language is to study
  388. examples written by more experienced programmers. The ARexx distribution disk
  389. includes a few example programs in the :rexx directory,and more programs will
  390. be added in future releases.
  391.  
  392. If you have written REXX language program(for any computer)that you think would
  393. be of interest to a more general audience,please send it to the author for
  394. consideration. Programs should be of interest either in terms of their specific
  395. funtionality or as an example of programming technique. Each program submitted
  396. should include an author credit and a few lines of commentary on its intended
  397. fuction.
  398.  
  399.                 2
  400.  
  401. ARexx is a high-level language useful for prototyping,software integration,and
  402. general programming tasks. It is an implementation of the REXX language
  403. described by M.F. Cowlishaw in The REXX Language:A Practical Approach to
  404. Programming(Prentice-Hall,1985),and follow the language definition closely.
  405. ARexx is particularly well suited as a command language. Command programs,
  406. sometimes called "scripts" or "macros",are widely used to extend the predefined
  407. commands of an operating system or to customize an applications program.
  408.  
  409. As a programming language,ARexx can be useful to a wide cross section of users.
  410. For the novice programmer,ARexx is an easy-to-learn yet powerful language that
  411. serves as a good introduction to programming techniques. Its source-level
  412. debugging facilities will help take some of the mystery out of how programs
  413. work(or don't work,as is more frequently the case.)
  414.  
  415. For the more sophisticated user,ARexx provides the means to build fully
  416. integrated software packages,combining different applications programs into an
  417. environment tailored to their needs. A common command language among
  418. applications that support ARexx will bring uniformity to procedural interfaces,
  419. much as the Amiga's Intuition provides uniformity in the graphical interface.
  420.  
  421. Finally,for the software developer,ARexx offers a straightforward way to build
  422. fully programmable applications programs. Developers can concentrate their
  423. efforts on making the basic operations of their programs fast and efficient,and
  424. let the end user add the frills and custom features.
  425.  
  426. 1-1 LANGUAGE FEATURES
  427.  
  428. Some of the important features of the language are:
  429.  
  430. TYPELESS DATA. Data are treated as typeless character strings. Variables do not
  431. have to be declared before being used,and all operations dynamically check the
  432. validity of the operands.
  433.  
  434. COMMAND INTERFACE. ARexx programs can issue commands to external programs that
  435. provide a suitable command interface. Any software package that implements the
  436. command interface is then fully programmable using ARexx,and can be extended
  437. and customized by the end user.
  438.  
  439. TRACING AND DEBUGGING. ARexx includes source-level debugging facilities that
  440. allow the programmer to see the step-by-step actions of a program as it runs,
  441. thereby reducing the time required to develop and test programs. An internal
  442. interrupt system permits special handling of errors that would otherwise cause
  443. the program to terminate.
  444.  
  445.                 3
  446.  
  447. INTERPRETED EXECUTION. ARexx programs are run by an interpreter,so separate
  448. compilation and linking steps are not required. This makes it especially useful
  449. for prototyping and as a learning tool.
  450.  
  451. FUNCTION LIBRARIES. External function libraries can be used to extend the
  452. capabilities of the language or as bridges to other programs. Libraries also
  453. allow ARexx programs to be used as "test drivers" for software development and
  454. testing.
  455.  
  456. AUTOMATIC RESOURCE MANAGEMENT. Internal memory allocation related to the
  457. creation and destruction of strings and other data structures is handled
  458. automatically.
  459.  
  460. 1-2 AREXX ON THE AMIGA
  461.  
  462. ARexx was designed to run on the Amiga,and makes use of many of the features of
  463. its multitasking operating system. ARexx programs run as separate tasks and
  464. may communicate with each other or with external programs. The interpreter
  465. follows the design guidelines expected of well-behaved programs in a
  466. multitasking environment: specifcally,it uses as little memory as possible and
  467. is careful to reutrn resources to the operating system when they are no longer
  468. needed. Memory requirements were minimized by implementing the entire ARexx
  469. system as a shared library,so that only one copy of the program code must be
  470. loaded.
  471.  
  472. 1-3 FURTHER INFORMATION
  473.  
  474. The aforementioned book by M.F. Cowlishaw is highly recommended to those
  475. interested in further information about REXX. It presents an interesting
  476. discussion of the design and development of the language.
  477.  
  478.                 4
  479.  
  480.             CHAPTER 2 GETTING ACQUAINTED
  481.  
  482. This chapter explains how to install ARexx on your Amiga computer and shows
  483. some example programs.
  484.  
  485. 2-1 INSTALLING AREXX
  486.  
  487. ARexx requires an Amiga computer with at least 256k of memory,and will operate
  488. under V1.1 or V1.2 of the operating system. It uses the double-precision math
  489. library called "mathieeedoubbas.library" that is supplied with the Amiga
  490. WorkBench disk,so make sure that this file is present in your LIBS: directory.
  491. The distribution disk includes the language system,some example programs,and a
  492. set of the INCLUDE files required for integrating ARexx with other software
  493. packages. The distribution files are listed in Appendix E.
  494.  
  495. AREXX AND WORKBENCH
  496.  
  497. ARexx can be installed and loaded from within the icon-based environment
  498. provided by the Amiga WorkBench. However,it is a primarily a text-oriented
  499. language system and requires a good text editor and file management environment
  500. to be most effective. Unless you purchased ARexx as part of an applications
  501. package that includes an integrated editor,you'll probably find it useful to
  502. become familiar with the Commmand Line Interface (CLI)environment on the Amiga.
  503.  
  504. INSTALLATION
  505.  
  506. The ARexx language system consists of a shared library,a resident program,and
  507. several command utilities. All of the required files are contained in the :c
  508. and :libs directories of the distribution disk. ARexx may be installed on any
  509. of the system disks with which it will be used,but first check the :c and :libs
  510. directores of each disk to make sure that there are no naming conflicts. The
  511. following steps will then install ARexx on the system disk,provided that two
  512. disk drives are available:
  513.  
  514. 1. Activate a CLI window.
  515. 2. Copy the ARexx :libs directory to the system LIBS: directory with the
  516. command "copy df1:libs to libs:".
  517. 3. Copy the ARexx :c directory to the system C: directory with the command
  518. "copy df1:C to c:".
  519.  
  520. SINGLE DRIVE SYSTEMS. Installing software in a single-drive system can be very
  521. confusing,so an installation utility has been provided with the ARexx
  522. distribution disk. It copies the :c and :libs directories of the distribution
  523. disk into memory,and then prompts the user to insert each disk that is to
  524. receive the files. Follow these steps to run the installation utility:
  525.  
  526.                 5
  527.  
  528. 1. Activate a CLI window.
  529. 2. Insert the distribution disk into drive 0 and type "df0:rxinstall".
  530. 3. At the program prompt,insert the system disk on which ARexx is to be
  531. installed into drive 0.
  532. 4. Repeat step 3 as required.
  533.  
  534. STARTING THE RESIDENT PROCESS
  535.  
  536. ARexx programs are launched by a background program called the resident
  537. process. It can be started by issuing the command rexxmast and must be active
  538. before any ARexx programs can be run. The rexxmast program briefly displays a
  539. small window to announce itself,and then disappears into the background to
  540. await your next request. If you will be using ARexx frequently,you can place
  541. the rexxmast command in the "startup-sequence" file that resides in the system
  542. S: directory. This will start the resident process automatically when you
  543. reboot the computer.
  544.  
  545. After the resident process has been loaded,ARexx programs can be run from the
  546. CLI by typing the command rx followed by the program name and any arguments.
  547. For example,the sample program calc.rexx,which evaluates an expression,could be
  548. run by typeing "rx :rexx/calc 1+1."
  549.  
  550. You may not need to start up the resident process if you are using a software
  551. package that starts it automatically. Applications that use ARexx can test
  552. whether the resident process is active by checking for a public message port
  553. named "REXX." If the port hasn't been opened,the program can issue the rexxmast
  554. command directly.
  555.  
  556. The resident process can be closed using the command rxc;it will then exit as
  557. soon as the last ARexx program finishes execution. Unless you are very short on
  558. memory space,there is usually no reason to close ARexx,as it simply waits in
  559. the background for the next program to run.
  560.  
  561. NAMING CONVENTIONS
  562.  
  563. ARexx programs can be named anything,but adopting a simple naming convention
  564. will make managing the programs much easier. Programs to be run from the CLI
  565. are usually given the file extention .rexx to distinguish them from programs
  566. written in other languages. Programs written as "macros" or "scripts" for a
  567. particular applications program should be given a file extension specific to
  568. that program. For example,a macro written for a communications program called
  569. "MyComm" might be named "download.myc". ARexx uses this file extention when it
  570. searches for a program file to be executed. 
  571.  
  572. THE REXX: DIRECTORY
  573.  
  574. You can designate one directory as the system-wide source for ARexx programs by
  575. defining a REXX: "device" with the assign command. This directory should reside
  576. on a volume that is usually mounted,such as SYS: or a hard disk. For example,
  577. the command "assign rexx: sys:rexx" defines the REXX: device as the :rexx
  578. directory on the system disk. Once defined,the REXX: device is searched after
  579. the current directory when looking for an ARexx program.
  580.  
  581.                 6
  582.  
  583. 2-2 PROGRAM EXAMPLES
  584.  
  585. Before introducing the structure and syntax of the language,let's look at a few
  586. examples of ARexx programs. Readers familiar with other high-level programming
  587. languages should find many points of similarity between ARexx and other
  588. languages. In the examples that follow,new terms are highlighted in the text as
  589. they are introduced,and will be convered in depth in the next few chapters.
  590.  
  591. These short programs can be created using any text editor and then run from the
  592. Command Line Interface (CLI),or may simply be read as samples of the language.
  593. If the examples are to be run,first complete the installation procedures
  594. outlined in the previous section,and then start the ARexx resident process.
  595. Example programs can then be run by entering,for example,"rx age" at the CLI
  596. prompt.
  597.  
  598. We'll begin with a "Hello,World" program that simply displays a message on the
  599. console screen.
  600.  
  601.     /* A simple program */
  602.     say 'Hello,World'
  603.  
  604. This program consists of a comment line that describes the program and an
  605. instruction that displays text on the console. For historical reasons, ARexx
  606. programs begin with a comment line;the initial "/*" says "I'm an ARexx program"
  607. to the interpreter when it searches for a program.
  608.  
  609. Instructions are language statements that denote a certain action to be
  610. performed,and always start with a symbol,in this case the word say. Symbols are
  611. translated to uppercase when the program is run,so the symbol say here is
  612. equivalent to SAY. Following say is an example of a string,which is a series of
  613. characters surrounded by quotes ('). Double quotes (") could also have been
  614. used to define the string.
  615.  
  616. In the next program we'll display a prompt for input and then read some
  617. information from the user.
  618.  
  619.     /* Calculate age in days */
  620.     say 'Please enter your age'
  621.     pull age
  622.     say 'You are about' age*365 'days old'
  623.  
  624. This program uses the pull instruction to read a line of input into a variable
  625. called age,which is then used with a say instuction. Variables are symbols that
  626. may be assigned a value. The words following say form an expression in which
  627. strings are joined and an arithmetic calculation is performed.
  628.  
  629. Note that the variable age did not have to be declared as a number;instead,its
  630. value was checked when it was actually used in the expression. To see what
  631. would happen if age wasn't a number,try rerunning the program with a
  632. non-numeric entry for the age. The resulting error message shows the line
  633. number and type of error that occurred,after which the program ends.
  634.  
  635.                 7
  636.  
  637. The next program introduces the do instruction,which allows program statements
  638. to be executed repeatedly. It also illustrates the exponentiation operator,
  639. which is used to raise a number to an integral power.
  640.  
  641.     /* Calculate some squares and cubes      */
  642.     do i = 1 to 10      /* 10 interations    */
  643.        say i i**2 i**3  /* calculations      */
  644.        end
  645.     say ' all done '
  646.  
  647. The do instruction causes the statements between the do and end instructions to
  648. be executed 10 times. The variable i is the index variable for the loop,and is
  649. incremented by 1 for each iteration. The number following the symbol to is the
  650. limit for the do instruction,and could have been a full expression rather than
  651. just the constant 10. Note that the statements within the loop have been
  652. indented. This is not required by the language,but it makes the program more
  653. readable and is therefore good programming practice.
  654.  
  655. The subject of the next example is the if instruction,a often-used control
  656. statement that allows statements to be conditionally executed. The numbers from
  657. 1 to 10 are classified as even or odd by dividing them by 2 and then checking
  658. the remainder.
  659.  
  660.     /* Even or odd? */
  661.     do i = 1 to 10
  662.        if i//2 = 0 then type = 'even'
  663.                    else type = 'odd'
  664.        say i 'is' type
  665.        end
  666.  
  667. This example intoduces the // arithmetic operator,which calculates the
  668. remainder after a division operation. The if instruction tests whether the
  669. remainder is 0 and executes the then branch if it is,thereby setting the
  670. variable type to "even." If the remainder was not 0,the alternative else branch
  671. is executed and type is set to "odd."
  672.  
  673. The next example introduces the concept of a function,which is a group of
  674. statements that can be executed by mentioning the function name in a suitable
  675. context. Functions are an important part of most programming languages,as they
  676. allow large,complex programs to be built from smaller modules. Functions are
  677. specified in an expression as a name followed by an open parenthesis. One or
  678. more expressions called arguments may follow the parenthesis;these are used to
  679. pass information to the function for processing.
  680.  
  681.                 8
  682.  
  683.     /* Defining and calling a function     */
  684.     do i = 1 to 5
  685.        say i square(i)     /* call square  */
  686.        end
  687.     exit            /* all done            */
  688.     square:        /* function name       */
  689.     arg x        /* get the "argument"  */
  690.     return x**2     /* square it and return*/
  691.  
  692. The function square is defined in the lines followed the label square: up
  693. through the return instruction. Two new instructions are introduced here: arg
  694. retrieves the value of the argument string,and return passes the functon's
  695. result back to the point where the function was called.
  696.  
  697. One final example will suffice for now. A new instruction called trace is used
  698. here to activate the tracing features of ARexx.
  699.  
  700.     /* Demonstrate "results" tracing */
  701.     trace results
  702.     sum=0;sumsq=0;
  703.     do i = 1 to 5
  704.        sum = sum + i
  705.        sumsq = sumsq + i**2
  706.        end
  707.     say 'sum=' sum 'sumsq=' sumsq
  708.  
  709. When this program is run,the console displays the source lines as they are
  710. excuted,and shows the final results of expressions. This makes it easy to tell
  711. what the program is really doing,and helps reduce the time required to develop
  712. and test a new program. One minor point is illustrated here: the third line
  713. shows two distinct statements separated by a semicolon (;). The semicolon is an
  714. example of a special character,characters that have particular meanings within
  715. ARexx programs.
  716.  
  717. The following chapters will present further information on the language
  718. statements illustrated here and will introduce others that have not been shown.
  719. Take heart,though;ARexx is a "small" language and there are relatively few
  720. words and rules to learn.
  721.  
  722.                 9
  723.  
  724. THERE WAS NO PAGE 10
  725.  
  726.             ELEMENTS OF THE LANGUAGE
  727.  
  728. This chapter introduces the rules and concepts that make up the REXX language.
  729. The intent is not to present a formalized definition,but rather to convey a
  730. practical understanding of how the language elements "fit together" to form
  731. programs.
  732.  
  733. 3-1 FORMAT
  734.  
  735. ARexx programs are compossed of ASCII characters and may be created using any
  736. text editor. No special formatting of the program statements is required or
  737. imposed on the programmer.
  738.  
  739. 3-2 TOKENS
  740.  
  741. The smallest distinct entities or "words" of the language are called tokens. A
  742. token may be series of characters,as in the symbol MyName,or just a single
  743. character like the "+" operator. Tokens can be categorized into comments,
  744. symbols,strings,operators,and special characters. Each of these groups are
  745. described below.
  746.  
  747. COMMENT TOKENS
  748.  
  749. Any group of characters beginning with the sequence "/*" and ending with "*/"
  750. defines a comment token. Comments may be placed anywhere in a program and cost
  751. little in terms of execution speed,since they are stripped(removed)when the
  752. program is first scanned by the interpreter. Comments may be "nested" within
  753. one another,but each "/*" must have a matching "*/" in the program.
  754. Examples:
  755.  
  756.     /* Your basic comment       */
  757.     /* a  /* nested! */ comment */
  758.  
  759. SYMBOL TOKENS
  760.  
  761. Any group of the characters a-z,A-Z,0-9,and .!?$_defines a symbol token.
  762. Symbols are translated to uppercase as the program is scanned by the
  763. interpreter,so the symbol MyName is equivalent to MYNAME. Four types of symbols
  764. are recognized:
  765.  
  766.     Fixed symbols begin with a digit (0-9) or a period(.).
  767.     Simple symbols do not begin with a digit,and do not contain any
  768.     periods.
  769.     Stem symbols have exactly one period at the end of the symbol name.
  770.     Compound symbols include one or more periods in the interior of the
  771.     name.
  772.  
  773. Stems and compound symbols have special properties that make them useful for
  774. building arrays and lists.
  775.  
  776.                 11
  777.  
  778. SYMBOLS VALUES. The value used for a fixed symbol is always the symbol name
  779. itself(as translated to uppercase.) Simple,stem,and compound symbols are called
  780. variables and may be assigned a value;the value used for an uninitialized
  781. variable is just the variable name itself.
  782. Examples:
  783.     
  784.     123.45        /*a fixed symbol    */
  785.     MyName        /*same as MyName    */
  786.     a.        /*a stem symbol        */
  787.     a.1.Index    /*a compound symbol    */
  788.  
  789. STRING TOKENS
  790.  
  791. A group of characters beginning and ending with a quote (')or double quote(")
  792. delimiter defines a string token. The delimiter character itself may be
  793. included within the string by a double-delimiter sequence (" or ""). The number
  794. of characters in the string is called its length,and a string of length zero is
  795. called a null string. A string is treated as a literal in an expression;that
  796. is,its value is just the string itself.
  797.  
  798. Strings followed immediately by an "X" or "B" character that is not part of a
  799. longer symbol are classified as hex or binary strings,respectively,and must be
  800. composed of hexadecimal digits(0-9,A-F) or binary digits(0,1). Blanks are
  801. permitted at byte boundaries for added readability. Hex and binary strings are
  802. convenient for specifying non-ASCII characters and for machine-specific
  803. information like addresses in a program. They are converted immediately to the
  804. "packed" internal form.
  805. Examples:
  806.     "Now is the time"    /*a simple example    */
  807.     ""            /*a null string        */
  808.     'Can't you see??'    /*Can't you see??    */
  809.     '4A 3B CO'X        /*a hex string        */
  810.     '00110111'b        /*binary for '7'    */
  811.  
  812. OPERATORS
  813.  
  814. The characters  +-*/=><*| may be combined in the sequences shown in Table 3.1
  815. to form operator tokens. Operator sequences may include leading,trailing,and
  816. embedded blanks,all of which are removed when the program is scanned. In
  817. addition to the above characters,the blank character as a concatenation
  818. operator if it follows a symbol or string and is not adjacent to an operator or
  819. special character.
  820.  
  821. Each operator has an associated priority that determines the order in which
  822. operations will be performed in an expression. Operators with higher priorities
  823. before those with lower priorities.
  824.  
  825.                 12
  826.  
  827.             TABLE 3.1 OPERATOR SEQUENCES
  828.  
  829. SEQUENCE        PRIORITY        OPERATOR DEFINITION
  830.  
  831.             8            Logical NOT
  832. +            8            Prefix Conversion
  833. -            8            Prefix Negation
  834. **            7            Exponentiation
  835. *            6            Multiplication
  836. /            6            Division
  837. %            6            Integer Division
  838. //            6            Remainder
  839. +            5            Addition
  840. -            5            Subtration
  841. ||            4            Concatenation
  842. (blank)            4            Blank Concatenation
  843. ==            3            Exact Equality
  844. ~==            3            Exact Inequality
  845. =            3            Equality
  846. ~=            3            Inequality
  847. >            3            Greater Than
  848. >=,~<            3            Greater Than or Equal To
  849. <            3            Less Than
  850. <=,~>            3            Less Than or Equal To
  851. &            2            Logical AND
  852. |            1            Logical Inclusive OR
  853. ^,&&            1            Logical Exclusive OR
  854.  
  855. SPECIAL CHARACTER TOKENS
  856.  
  857. The characters :():,are each treated as a separate special character token and
  858. have particular meanings within an ARexx program. Blanks adjacent to these
  859. special characters are removed,except for those preceding an open parenthesis
  860. or following a close parenthesis.
  861.  
  862. COLON (:). A colon,if preceded by a symbol token,defines a label within the
  863. program. Lavels are locations in the program to which control may be
  864. transferred under various conditions.
  865.  
  866. OPENING AND CLOSING PARENTHESES (()). Parentheses are used in expressions to
  867. group operators and operands into subexpressions,in order to override the
  868. normal operator primorities. An open parenthesis also serves to identify a
  869. function call within an expression;a symbol or string followed immediately by
  870. an open parenthesis defines a function name. Parentheses must always be
  871. balanced within a statement.
  872.  
  873. SEMICOLON (;). The semicolon acts as a program statement terminator. Several
  874. statements may be placed on a single source line if separated by semicolons.
  875.  
  876.                 13
  877.  
  878. COMMA (,). A comma token acs as the continuation character for statements that
  879. must be entered on several source lines. It is also used to separate the
  880. argument expressions in a function call.
  881.  
  882. 3-3 CLAUSES
  883.  
  884. Tokens are grouped together to form clauses,the smallest language unit that can
  885. be executed as a statement. Every clause in ARexx can be classified as either a
  886. null,label,assignment,instruction,or command clause. The classification process
  887. is very simple,since no more than two tokens are required to classify any
  888. clause. Assignment,instruction,and command clauses are jointly termed
  889. statements.
  890.  
  891. CLAUSE CONTINUATION. The end of a source line normally acts as the implicit end
  892. of a clause. A clause can be continued on the next source line by ending the
  893. line with a comma (,). The commas is then removed,and the next line is
  894. considered as a continuation of the clause. There is no limit to the number of
  895. continuations that may occur. String and comment tokens are automatically
  896. continued if a line end before the closing delimiter has been found,and the
  897. "newline" character is not considered to be part of the token.
  898.  
  899. MULTIPLE CLAUSES. Several clauses can be placed on a single line by separating
  900. them with semicolons(;).
  901.  
  902. NULL CLAUSES
  903.  
  904. Lines consisting only of blanks or comments are called null clauses. They have
  905. no function in the execution of a program,except to aid its readability and to
  906. increment the source line count. Null clauses may appear anywhere in a program.
  907. Example:
  908.  
  909.     /* perform annuity calculations        */
  910.  
  911. LABEL CLAUSES
  912.  
  913. A symbol followed immediately by a colon defines a label clause. A label acts
  914. as a placemarker in the program,but no action occurs with the "execution" of a
  915. label. The colon is considered as an implicit clause terminator,so each label
  916. stands as a separate clause. Label clauses may appear anywhere in a program.
  917. Examples:
  918.  
  919.     start:        /* begin execution    */
  920.     syntax:        /* error processing    */
  921.  
  922. ASSIGNMENT CLAUSES
  923.  
  924. Assignments are identified by a variable symbol followed by an "=" operator. In
  925. this context the operator's normal definition(an equality comparison)is
  926. overridden,and it becomes an assignment operator. The tokens to the right of
  927. the "=" are evaluated as an expression,and the result is assigned to(becomes
  928. the value of)the variable symbol.
  929.  
  930.                 14
  931.  
  932. Examples:
  933.  
  934.     when= 'Now is the time'
  935.     answ= 3.14 * fact(5)
  936.  
  937. INSTRUCTION CLAUSES
  938.  
  939. Instructions begin with certain keyword symbols,each of which denotes a
  940. particular action to be performed. Instruction keywords are recognized as such
  941. only at the beginning of a clause,and may otherwise be used freely as symbols
  942. (although such use may become confusing at times.) The ARexx instructions are
  943. described in detail in Chapter 4. 
  944. Examples:
  945.  
  946.     drop a b c        /* reset variables    */
  947.     say 'please'        /* a polite program    */
  948.     if j > 5 then leave;    /* several instructions    */
  949.  
  950. COMMAND CLAUSES
  951.  
  952. Commands are any ARexx expression that can't be classified as one of the
  953. preceding types of clauses. The expression is evaluated and the result is
  954. issued as a command to an external host,which might be the native operating
  955. system or an application program. Commands are discussed in Chapter 5,and the
  956. details of the host command interface are given in Chapter 10.
  957. Examples:
  958.  
  959.     'delete' 'myfile'    /* a DOS command    */
  960.     'jump' current+10    /* an editor command?    */
  961.  
  962. CLAUSE CLASSIFICATION
  963.  
  964. The process by which program lines are divided into clauses and then classified
  965. is important in understanding the operation of an ARexx program. The language
  966. interpreter splits the program source into groups of clauses as the program is
  967. read,using the end of each line as a clause separator and applying the
  968. continuation rule as required. These groups of one or more clauses are then
  969. tokenized,and each clause is classified into one of the above types. Note that
  970. seemingly small syntactic differences may completely change the semantic
  971. content of a statement. For example,
  972.  
  973.     SAY 'Hello, Bill'
  974.  
  975. is an instruction clause and will display "Hello, Bill" on the console,but
  976.  
  977.     ""SAY 'Hello, Bill'
  978.  
  979. is a command clause,and will issue "SAY Hello, Bill" as a command to an
  980. external program. The presence of the leading null string changes the
  981. classification from an instruction clause to a command clause.
  982.  
  983.                 15
  984.  
  985. 3-4 EXPRESSIONS
  986.  
  987. Expression evaluation is an important part of ARexx programs,since most
  988. statements include at least one expression. Expressions are composed of
  989. strings,symbols,operators,and parentheses. Strings are used as literals in an
  990. expression;their value in an operation is just the string itself. Fixed symbols
  991. are also literals(remember that symbols are always translated to uppercase,)
  992. but variable symbols may have an assigned value. Operator tokens represent the
  993. predefined operations of ARexx;each operator has an associated priority that
  994. determines the order in which operations will be performed. Parentheses may be
  995. used to alter the normal order of evaluation in the expression,or to identify
  996. function calls. A symbol or string followed immediately by an open parenthesis
  997. defines the function name,and the tokens between the opening and(final)closing
  998. parenthesis form the argument list for the function.
  999.  
  1000. For example,the expression "J 'fractorial is' fact(J)" is composed of a symbol
  1001. J,a blank operator,the string 'factorial is',another blank,the symbol fact,an
  1002. open parenthesis,the symbol J again,and a closing parenthesis. FACT is a
  1003. function name and (J) is its argument list,in this case the single expression
  1004. J.
  1005.  
  1006. SYMBOL RESOLUTION
  1007.  
  1008. Before the evaluation of an expression can proceed,the interpreter must obtain
  1009. a value for each symbol in the expression. For fixed symbols the value is just
  1010. the symbol name itself,but variable symbols must be looked up in the current
  1011. symbol table. In the example above,the expression after symbol resolution would
  1012. be "3 'factorial is' FACT(3)," assuming that the symbol J had the value 3.
  1013.  
  1014. Suppose that the example above had been "FACT(J) 'is' J 'factorial'." Would the
  1015. second occurrence of symbol J still resolve to 3 in this case? In general,
  1016. function calls may have "side effects" that include altering the values of
  1017. variables,so the value of J might have been changed by the call to FACT. In
  1018. order to avoid ambiguities in the values assigned to symbols during the
  1019. resolution process, ARexx guarantees a strict left-to-right resolution order.
  1020. Symbol resolution proceeds irrespective of operator priority or parenthetical
  1021. grouping;if a function call is found,the resolution is suspended while the
  1022. function is evaluated. Note that it is possible for the same symbol to have
  1023. more than one value in an expression.
  1024.  
  1025. ORDER OF EVALUATION
  1026.  
  1027. After all symbol values have been resolved,the expression is evaluated based on
  1028. operator priority and subexpression grouping. Operators of higher priority are
  1029. evaluated first. ARexx does not guarantee an order of evaluation among
  1030. operators of equal priority,and does not employ a "fast path" evaluation of
  1031. boolean operators. For example,in the expression
  1032.  
  1033.     (1 = 2) & (FACT(3) = 6)
  1034.  
  1035. the call to the FACT function will be made,although it is clear that the final
  1036. result will be 0,since the first term of the AND operation is 0.
  1037.  
  1038.                 16
  1039.  
  1040. 3-5 NUMBERS AND NUMERIC PRECISION
  1041.  
  1042. An important class of operands are those representing numbers. Numbers consist
  1043. of the characters 0-9,.+-,and blanks;an e or E may follow a number to indicate
  1044. exponential notation,in which case it must be followed by a (signed) integer).
  1045.  
  1046. Both string tokens and symbol tokens may be used to specify numbers. Since the
  1047. language is typeless,variables do not have to be declared as "numeric" before
  1048. being used in an arithmetic operation. Instead,each value string is examined
  1049. when it is used to verify that it represents a number. The following examples
  1050. are all valid numbers:
  1051.  
  1052.     33
  1053.     "   12.3   "
  1054.     0.321e12
  1055.     ' + 15.'
  1056.  
  1057. Note that leading and trailing blanks are permitted,and that blanks may be
  1058. embedded between a "+" or "-" sign and the number body(but not within the
  1059. body.)
  1060.  
  1061. BOOLEAN VALUES
  1062.  
  1063. The numbers 0 and 1 are used to represent the boolean values False and True,
  1064. respectively. The use of a value other than 0 or 1 when a boolean operand is
  1065. expected will generate an error. Any number equivalent to 0 or 1,for example
  1066. "0.000" or "0.1E1," is also acceptable as a boolean value.
  1067.  
  1068. NUMERIC PRECISION
  1069.  
  1070. ARexx allows the basic precision used for arithmetic calculations to be
  1071. modified while a program is executing. The number of significant figures used
  1072. in arithmetic operations is determined by the Numeric Digits environment
  1073. variable, and may be modified using the NUMERIC instruction.
  1074.  
  1075. The number of decimal places used for a result depends on the operation
  1076. performed and the number of decimal places in the operands. Unlike many
  1077. languages,ARexx preserves trailing zeroes to indicate the precision of the
  1078. result. If the total number of digits required to express a value exceeds the
  1079. current Numeric Digits setting,the number is formatted in exponential notation.
  1080. Two such formats are provided:
  1081.  
  1082. In SCIENTIFIC notation,the exponent is adjusted so that a single digit is
  1083. placed to the left of the decimal point.
  1084.  
  1085. in ENGINEERING notation,the number is scaled so that the exponent is a multiple
  1086. of 3 and the digits to the left of the decimal point range from 1 to 999.
  1087.  
  1088. The numeric precision and format can be set using the NUMERIC instruction.
  1089.  
  1090.                 17
  1091.  
  1092. 3-6 OPERATORS
  1093.  
  1094. Operators can be grouped into four categories:
  1095.  
  1096. Arithmetic operators require one or two numeric operands,and produce a numeric
  1097. result.
  1098. Concatenation operators join two strings into a single string.
  1099. Comparison operators require two operands,and produce a boolean(0 or 1) result.
  1100. Logical Operators require one or two boolean operands,and produce a boolean
  1101. result.
  1102.  
  1103. ARITHMETIC OPERATORS
  1104.  
  1105. The aritmetic operators are listed in Table 3.2 below. Note the inclusion of
  1106. the integer division(%)and remainder(//)operators,along with the usual
  1107. arithmetic operations. The result of an arithmetic operation is always foratted
  1108. based on the current Numeric Digits setting,and will never have leading or
  1109. trailing blanks.
  1110.  
  1111.             TABLE 3.2 ARITHMETIC OPERATORS
  1112.     SEQUENCE        PRIORITY        OPERATION
  1113.     +            8            Prefix Conversion
  1114.     -            8            Prefix Negation
  1115.     **            7            Exponentiation
  1116.     *            6            Multiplication
  1117.     /            6            Division
  1118.     %            6            Integer Division
  1119.     //            6            Remainder
  1120.     +            5            Addition
  1121.     -            5            Subtraction
  1122.  
  1123. PREFIX CONVERSION(+). This unary operator converts the operand to and internal
  1124. numeric form and formats the result based on the current Numeric Digits
  1125. settings. This causes any leading and trailing blanks to be removed,and may
  1126. result in a loss of precision.
  1127. Examples:
  1128.  
  1129.     '  3.12 '        ==> 3.12
  1130.     1.5001            ==> 1.500 /* If digits = 3  */
  1131.  
  1132. PREFIX NEGATION(-). This unary operator negates the operand. The result is
  1133. formatted based on the current Numeric Digits setting.
  1134.  
  1135.                 18
  1136.  
  1137. Examples:
  1138.  
  1139.     -'  3.12 '        ==> -3.12
  1140.     1.5E2            ==>-150
  1141.  
  1142. EXPONENTIATION(**). The left operand is raised to the power specified by the
  1143. right operand,which must be an integer. The number of decimal places for the
  1144. result is the product of the exponent and the number of decimal places in the
  1145. base.
  1146. Examples:
  1147.  
  1148.     2**3            ==>8
  1149.     3**-1            ==>.333333333
  1150.     0.5**3            ==>0.125
  1151.  
  1152. MULTIPLICATION(*). The product of two numbers is computed. The number of
  1153. decimal places for the result is the sum of the decimal places of the operands.
  1154. Examples:
  1155.  
  1156.     12 * 3            ==>36
  1157.     1.5 * 1.50        ==>2.250
  1158.  
  1159. DIVISION(/). The quotient of two numbers is computed. The number of decimal
  1160. places for the result depends on the current setting of the numeric DIGITS
  1161. variable;the nuber is formatted to the maximum precision required.
  1162. Examples:
  1163.  
  1164.     6 / 3            ==>2
  1165.     8 / 3            ==>2.66666667
  1166.  
  1167. INTEGER DIVISION(%). The quotient of two numbers is computed,and the integer
  1168. part of the quotient is used as the result.
  1169. Examples:
  1170.  
  1171.     5 % 3            ==>1
  1172.     -8 % 3            ==>-2
  1173.  
  1174. REMAINDER(//). The result is the remainder after the two operands are divided.
  1175. The remainder for "a//b" is calculated as "a-(a%b)*b." If both operands are
  1176. positive integers,this operation yields the usual "modulo" result.
  1177.  
  1178.                 19
  1179.  
  1180. Examples:
  1181.  
  1182.     5 // 3            ==>2
  1183.     -5 // 3            ==>-2
  1184.     5.1 // 0.2        ==>0.1
  1185.  
  1186. ADDITION(+). The sum of two numbers is computed. The number of decimal places
  1187. for the result is the larger of the decimal places of the operands.
  1188. Examples:
  1189.  
  1190.     12 + 3            ==>15
  1191.     3.1 + 4.05        ==>7.15
  1192.  
  1193. SUBTRATION(-). The difference of two numbers is computed. As in the case of
  1194. addition,the number of decimals places for the result is the larger of the
  1195. decimal places of the operands.
  1196. Examples:
  1197.  
  1198.     12 - 3            ==>9
  1199.     5.55 - 1.55        ==>4.00
  1200.  
  1201. CONCATENATION OPERATORS
  1202.  
  1203. ARexx defines two concatenation operators,both of which require two operands.
  1204. The first,identified by the operator sequence "||",joins two strings into a
  1205. single string with no intervening blank. The second concatenation operation is
  1206. identified by the blank operator,and joins the two operand strings with one
  1207. intervening blank.
  1208.  
  1209. An implicit concatenation operator is recognized when a symbol and a string are
  1210. directly abutted in an expression. Concatenation by abuttal uses the "||"
  1211. operator,and behaves exactly as though the operator had been provided
  1212. explicitly.
  1213. Examples:
  1214.  
  1215.     'why me,' || 'Mom?'        ==>why me,Mom?
  1216.     'good' 'times'            ==>good times
  1217.     one'two'three            ==>ONEtwoTHREE
  1218.  
  1219. COMPARISON OPERATORS
  1220.  
  1221. Comparisons are performed in one of three modes,and always result in a boolean
  1222. value(0 or 1.)
  1223.  
  1224. Exact comparisons proceed character-by-character,including any leading blanks
  1225. that may be present.
  1226. String comparisons ignore leading blanks,and pad the shorter string with blanks
  1227. if necessary.
  1228.  
  1229.                 20
  1230.  
  1231. Numeric comparisons first convert the operands to an internal numeric form
  1232. using the current Numeric Digits setting,and then perform a standard arithmetic
  1233. comparison.
  1234.  
  1235. Except for the exact equality and exact inequality operators,all comparison
  1236. operators dynamically determine whether a string of numeric comparison is to be
  1237. performed. A numeric comparison is performed if both operands are valid numbers
  1238. otherwise,the operands are compared as strings.
  1239.  
  1240.             TABLE 3.3 COMPARISON OPERATORS
  1241.  
  1242. SEQUENCE    PRIORITY    OPERATION        MODE
  1243.  
  1244. ==        3        Exact Equality        Exact
  1245. ~==        3        Exact Inequality    Exact
  1246. =        3        Equality        String/Numeric
  1247. ~=        3        Inequality        String/Numeric
  1248. >        3        Greater Than        String/Numeric
  1249. >=,~<        3        Greater Than or Equal    String/Numeric
  1250. <        3        Less Than        String/Numeric
  1251. <=,~>        3        Less Than or Equal    String/Numeric
  1252.  
  1253. LOGICAL (BOOLEAN) OPERATORS
  1254.  
  1255. ARexx defines the four logical operations NOT,AND,OR,and Exclusive OR,all of
  1256. which require boolean operands and produce a boolean result. Boolean operands
  1257. must have values of either 0(False)or 1(True.) An attempt to perform a logical
  1258. operation on a non-boolean operand will generate an error.
  1259.  
  1260.             TABLE 3.4 LOGICAL OPERATORS
  1261.  
  1262.     SEQUENCE    PRIORITY    OPERATION
  1263.  
  1264.     ~        8        NOT(Inversion)
  1265.     &        2        AND
  1266.     |        1        OR
  1267.     ^,&&        1        Exclusive OR
  1268.  
  1269. 3-7 STEMS AND COMPOUND SYMBOLS
  1270.  
  1271. Stems and compound symbols have special properties that allow for some
  1272. interesting and unusual programming. A compound symbol can be regarded as
  1273. having the structure stem.n1.n2.n3...nk where the leading name is a stem symbol
  1274. and each node n1...nk is a fixed or simple symbol. Whenever a compound symbol
  1275. appears in a program,its name is expanded by replacing each node with its
  1276. current value as a (simple) symbol. The value string may consist of any
  1277. characters,including embedded blanks,and is not converted to uppercase. The
  1278. result of the expansion is a new name that is used in place of the compound
  1279. symbol. For example if j has the value of 3 and k has the value 7,then the
  1280. compound symbol a.j.k will expand to A.3.7.
  1281.  
  1282. Stem symbols provide a way to initialize a whole class of compound symbols.
  1283. When an assignment is made to a stem symbol,it assigns that value to all
  1284. possible compound symbols derived from the stem. Thus,the value of a compound
  1285. symbol depends on the prior assignments made to itself or its associated stem.
  1286.  
  1287.                 21
  1288.  
  1289. Compound symbols can be regarded as a form of "associative" or "content-
  1290. addressable" memory. For example,suppose that you needed to store and retrieve
  1291. a set of names and telephone numbers. The conventional approach would be to set
  1292. up two arrays NAME and NUMBER,each indexed by an integer running from one to
  1293. the number of entries. A number would be "looked up" by scanning the name array
  1294. until the given name was found,say in NAME.12,and then retrieving NUMBER.12.
  1295. With compound symbols,the symbol NAME could hold the name to be looked-up,and
  1296. NUMBER.NAME would then expand to NUMBER.Bill(for example),which be the
  1297. corresponding number.
  1298.  
  1299. Of course,compound symbols can also be used as conventional indexed arrays,with
  1300. the added convenience that only a single assignment(to the stem)is required to
  1301. initialize the entire array.
  1302.  
  1303. 3-8 THE EXECUTION ENVIRONMENT
  1304.  
  1305. The ARexx interpreter provides a uniform environment by running each program as
  1306. a separate task(actually,as a DOS process)in the Amiga's multitasking operating
  1307. system. This allows for a flexible interface between an external host program
  1308. and the interpreter,as the host can either proceed concurrently with its
  1309. operations or can simply wait for the interpreted program to finish.
  1310.  
  1311. THE EXTERNAL ENVIRONMENT
  1312.  
  1313. The external environment of a program includes its task(process)structure,
  1314. input and output streams,and current directory. When each ARexx task is
  1315. created,it inherits the input and output streams and current directory from its
  1316. client,the external program that invoked the ARexx program. The current
  1317. directory is used as the starting point in a search for a program or data file.
  1318.  
  1319. EXTERNAL PROGRAMS. The external environment usually includes one or more
  1320. external programs with which the ARexx program may communicate. Any program
  1321. that supports a suitable interface can receive commands from ARexx programs.
  1322. The command interface is discussed in Chapter 5.
  1323.  
  1324. THE INTERNAL ENVIRONMENT
  1325.  
  1326. The internal environment of an ARexx program consists of a static global
  1327. structure and one or more storage environments. The global data values are
  1328. fixed at a time the program is invoked,and include the argument strings,program
  1329. source code,and static data strings. The storage environment includes the
  1330. symbol table used for variable values,the numeric options,trace options,and
  1331. host address strings. While the global environment is unique,there may be many
  1332. storage environments during the course of the program execution. Each time an
  1333. internal function is called a new storage environment is activated and
  1334. initialized. The initial values for most fields are inherited from the previous
  1335. environment,but values may be changed afterwards without affecting the caller's
  1336. environment. The new environment persists until control returns from the
  1337. function.
  1338.  
  1339.                 22
  1340.  
  1341. ARGUMENT STRINGS. A program may receive one or more argument strings when it is
  1342. first invoked. These arguments persist for the duration of the program and are
  1343. never altered. The number of arguments a program receives depends in part on
  1344. the mode of invocation. ARexx programs invoked as commands normally have only
  1345. one argument string,although the "command tokenization" option may provide more
  1346. than one. A program invoked as a function can have any number of arguments if
  1347. called as an internal function,but external functions are limited to a maximum
  1348. of 15 arguments.
  1349.  
  1350. The argument strings can be retrieved using either the ARG instruction or the
  1351. ARG() Built-In function. ARG() can also return the total number of arguments,or
  1352. the status(as "exists" or "omitted")of a particular argument.
  1353.  
  1354. THE SYMBOL TABLE. Every storage environment includes a symbol table to store
  1355. the value strings that have been assigned to variables. This symbol table is
  1356. organized as a two-level stores entries for simple and stem symbols,and the
  1357. secondary level is used for compound symbols. All of the compound symbols
  1358. associated with a particular stem are stored in one tree,with the root of the
  1359. tree held by the entry for the stem.
  1360.  
  1361. Symbols are not entered into the table until an assignment is made to the
  1362. symbol. Once created,entries at the primary level are never removed,even if the
  1363. symbol subsequently becomes uninitialized. Secondary trees are released
  1364. whenever an assignment is made to the stem associated with the tree.
  1365.  
  1366. For the most part ARexx programmers need not be concerned with the details of
  1367. storage environments except to understand what values are saved when a function
  1368. is called. Applications developers who need to manipulate environment values
  1369. should refer to the structure definitions in the INCLUDE files provided on the
  1370. ARexx distribution disk.
  1371.  
  1372. INPUT AND OUTPUT
  1373.  
  1374. Most computer programs require some means of communicating with the outside
  1375. world,either to accept input data or to pass along results. The REXX language
  1376. includes only a minimal specification of input and output (I/O)operations,
  1377. leaving the choice of additional functionality to the language implementor.
  1378. This is in keeping with the design of many computer languages. For instance,the
  1379. "C" language has no statements dedicated to I/O,but instead relies on a
  1380. standardized set of I/O functions.
  1381.  
  1382. ARexx extends the I/O facilities fo REXX by providing Built-In functions to
  1383. manipulate external files. Files are referenced by a logical name associated
  1384. with the file when it is first opened. The initial input and output streams are
  1385. given the names STDIN and STDOUT.
  1386.  
  1387. ARexx maintains a list of all of the files opened by a program and
  1388. automatically closes them when the program finishes. There is no limit to the
  1389. number of files that may be open simultaneously.
  1390.  
  1391.                 23
  1392.  
  1393. RESOURCE TRACKING
  1394.  
  1395. ARexx provides complete tracking for all of the dynamically-allocated resources
  1396. that it uses to execute a program. These resources include memory space,DOS
  1397. files and related structures,and the message port structures supported by
  1398. ARexx. The tracking system was designed to allow a program to "bail out" at any
  1399. point(perhaps due to an execution error)without leaving any hanging resources.
  1400.  
  1401. It is possible to go outside of the interpreter's resource tracking net by
  1402. making calls directly to the Amiga's operating system from within an ARexx
  1403. program. In these cases it is the programer's responsibility to track and
  1404. return all of the allocated resources. ARexx provides a special interrupt
  1405. facility so that a program can retain control after an execution error,perform
  1406. the required cleanup,and then make an orderly exit. Chapter 7 has information
  1407. on the ARexx interrupt system.
  1408.  
  1409.                 24
  1410.  
  1411.             CHAPTER 4  INSTRUCTIONS
  1412.  
  1413. Instruction clauses are identified by an initial keyword symbol that is not
  1414. followed by a colon(:)or an equals(=)operator. Each instruction signifies a
  1415. specific action,and may be followed by one or more subkeywords,expressions,or
  1416. other instruction-specific information. Instruction keywords and subkeywords
  1417. are recognized only in this specific context,and are therefore not "reserved
  1418. words" in the usual sense of the term. Keywords may be used freely as variables
  1419. or function names,although such usage may become confusing at times.
  1420.  
  1421. In the descriptions that follow,keywords are shown in uppercase and optional
  1422. parts of the instruction are enclosed in brackets. Alternative selections are
  1423. separated by a vertical bar(|),and required alternative are enclosed in braces
  1424. ({}).
  1425.  
  1426. 4-1 ADDRESS
  1427.  
  1428. Usage: ADDRESS [Symbol|string|VALUE] [expression]]
  1429. This instruction specifies a host address for commands issued by the
  1430. interpreter. A host address is the name associated with an external program to
  1431. which commands can be sent;external hosts are described in Chapter 5. ARexx
  1432. maintains two host addresses:a "current" and a "previous"address is lost,and
  1433. the "current" and a "previous" value. Whenever a new host address is supplied,
  1434. the "previous" address is lost,and the "current" address becomes the "previous"
  1435. one. These host addresses are part of a program's storage environment and are
  1436. preserved across internal function calls. The current address can be retrieved
  1437. with the Built-In function ADDRESS(). There are four distinct forms for the
  1438. ADDRESS instruction:
  1439.  
  1440. ADDRESS {string | symbol} expression. The expression is evaluated and the
  1441. result is issued to the host specified by the string or symbol,which is taken
  1442. as a literal. No changes are made to the current or previous address strings.
  1443. This provides a convenient way to issue a single command to an external host
  1444. without disturbing the current host addresses. The return code from the command
  1445. is treated as it would be from a command clause.
  1446.  
  1447. ADDRESS {string | symbol}. The string or symbol,taken as a literal,specifies
  1448. the new host address. The current host address becomes the previous address.
  1449.  
  1450. ADDRESS [VALUE] expression. The result of the expression specifies the new host
  1451. address,and the current address becomes the previous address. The VALUE keyword
  1452. may be omitted if the first token of the expression is not a symbol or string.
  1453.  
  1454. ADDRESS. This form interchanges the current and previous hosts. Repeated
  1455. execution will therefore "toggle" between the two host addresses.
  1456.  
  1457.     Examples:
  1458.  
  1459. address edit        /* set an new host address       */
  1460. address edit 'top'    /* move to the top        */
  1461. address VALUE edit n    /* compute a new host address    */
  1462. address            /* swap current and previous    */
  1463.  
  1464.                 25
  1465.  
  1466. Usage: ARG [template] [,template...]
  1467. ARG is shorthand form for the PARSE UPPER ARG instruction. It retrieves one or
  1468. more of the argument strings available to the program,and assigns values to the
  1469. variables in the template. The number of argument strings available depends on
  1470. the whether the program was invoked as a command or a function. Command
  1471. invocations normally have only one argument string,but functions may have up to
  1472. 15. The argument strings are not altered by the ARG instruction.
  1473.  
  1474. The structure and processing of templates is described briefly with the PARSE
  1475. instruction,and in greater depth in Chapter 8.
  1476.     Example:
  1477.  
  1478. arg first,second /* fetch arguments */
  1479.  
  1480. 4-3 BREAK
  1481.  
  1482. Usuage: BREAK
  1483. The BREAK instruction is used to exit from the range of a DO instruction or
  1484. from within an INTERPRETed string,and is valid only in these contexts. If used
  1485. within a DO statement,BREAK exits from the innermost DO statement containing
  1486. the BREAK. This contrasts with the otherwise similar LEAVE instruction,which
  1487. exits only from an interative DO.
  1488.     Example:
  1489.  
  1490. do            /* begin block        */
  1491.   if i>3 then break    /* all done?        */
  1492.   a = a + 1
  1493.   y.a = name
  1494.   end            /* end block        */
  1495.  
  1496. 4-4 CALL
  1497.  
  1498. Usage: CALL {symbol | string} [expression] [,expression,...]
  1499. The CALL instruction is used to invoke an internal or external function. The
  1500. function name is specified by the symbol or string token,which is taken as a
  1501. literal. Any expressions that follow are evaluated and become the arguments to
  1502. the called function. The value returned by the function is assigned to the
  1503. special variable RESULT. It is not an error if a result string is not returned;
  1504. in this case the variable RESULT is DROPed(becomes uninitialized.)
  1505.  
  1506. The linkage to the function is established dynamically at the time of the call.
  1507. ARexx follows a specific search order in attempting to locate the called
  1508. function;this process is described in Chapter 6.
  1509.     Example:
  1510.  
  1511. call center name,length+4,'+'
  1512.  
  1513.                 26
  1514.  
  1515. Usage: DO [var=exp] [To exp] [BY exp]] [FOR exp] [FOREVER] [WHILE exp | UNTIL
  1516. exp]
  1517. The DO instruction begins a group of instructions to be executed as a block.
  1518. The range of the DO instruction includes all statements up to and including an
  1519. eventual END instruction. There are two basic forms of the instruction:
  1520.  
  1521. The DO keyword by itself defines a block of instructions to be executed once.
  1522.  
  1523. If any iteration specifiers follow the DO keyword,the block of instructions is
  1524. executed repeatedly until a termination condition occurs.
  1525.  
  1526. An interative DO instruction is sometimes called a "loop",since the interpreter
  1527. "loops back" to perform the instruction repeatedly. The various parts of the DO
  1528. instruction are described below.
  1529.  
  1530. Initializer expression. An initializer expression of the form "variable=
  1531. expression" defines the index variable of the loop. The expression is evaluated
  1532. when the DO range is first activated,and the result is assigned to the index
  1533. variable. On subsequent iterations an expression of the form "variable =
  1534. variable + increment" is evaluated,where the increment is the result of the BY
  1535. expression. If specified, the initializer expression must precede any of the
  1536. other subkeywords.
  1537.  
  1538. BY expression. The expression following a BY symbol defines the increment to be
  1539. added to the index variable in each subsequent iteration. The expression must
  1540. yield a numeric result,which may be positive or negative and need not be an
  1541. integer. The default increment is 1.
  1542.  
  1543. TO expression. The result of the TO expression specifies the upper(or lower)
  1544. limit for the index variable. At each iteration the index variable is compared
  1545. to the TO result. If the increment(BY result)is positive and the variable is
  1546. greater than the limit,the DO instruction terminates and control passes to the
  1547. statement following the END instruction. Similarly,the loop terminates if the
  1548. increment is negative and the index variable is less than the limit.
  1549.  
  1550. FOR expression. The FOR expression must yield a positive whole number when
  1551. evaluated,and specifies the maximum number of iterations to be performed. The
  1552. loop terminates when this limit is reached irrespective of the value of the
  1553. index variable.
  1554.  
  1555. FOREVER. The FOREVER keyword can be used if an iterative DO instruction is
  1556. required but no index variable is necessary. Presumably the loop will be
  1557. terminated by a LEAVE or BREAK instruction contained within the loop body.
  1558.  
  1559. WHILE expression. The WHILE expression is evaluated at the beginning of each
  1560. iteration and must result in a boolean value. The iteration proceeds if the
  1561. result is 1;otherwise,the loop terminates.
  1562.  
  1563.                 27
  1564.  
  1565. UNTIL expression. The UNTIL expression is evaluated at the end of each
  1566. iteration and must result in a boolean value. The instruction continues with
  1567. the next iteration if the result is 0,and terminates otherwise.
  1568.  
  1569. The initializer,BY,TO,and FOR expressions are evaluated only when the
  1570. instruction is first activated,so the increment and limits are fixed throughout
  1571. the execution. Note that a limit need not be supplied;for example,the
  1572. instruction "DO i=1" will simply count away forever. Note also that only one of
  1573. the WHILE or UNTIL keywords can be specified.
  1574. Example:
  1575.  
  1576. do i=1 to limit for 5 while time <50
  1577.    y.1=i*time
  1578.    end
  1579.  
  1580. 4-6 DROP
  1581.  
  1582. Usage: DROP variable [variable...]
  1583. The specified variable symbols are reset to their uninitialized state,in which
  1584. the value of the variable is the variable name itself. It is not an error to
  1585. DROP a variable that is already uninitialized. DROPping a stem symbol is
  1586. equivalent to DROPping the values of all possible compound symbols derived from
  1587. that stem.
  1588. Example:
  1589.  
  1590. a=123        /* assign a value    */
  1591. drop a b    /* drop some        */
  1592. say a b        /* ==>A B        */
  1593.  
  1594. 4-7 ECHO
  1595.  
  1596. Usage: ECHO [expression]
  1597. The ECHO instruction is a synonym for the SAY instruction. It displays the
  1598. expression result on the console.
  1599. Example:
  1600.  
  1601. echo  "You don't SAY!"
  1602.  
  1603. 4-8 ELSE
  1604.  
  1605. Usage: ELSE [;] [conditional statement]
  1606. The ELSE instruction provides the alternative conditional branch for an IF
  1607. statement. It is valid only within the range of an IF instruction,and must
  1608. follow the conditional statement of the THEN branch. If the THEN branch wasn't
  1609. executed,the statement following the ELSE clause is performed.
  1610.  
  1611. Binding. ELSE clauses always bind to the nearest(preceding)IF statement. It may
  1612. be necessary to provide "dummy" ELSE clauses for the inner IF ranges of a
  1613. compound IF statement in order to allow alternative branches for the outer IF
  1614. statements. In this case it is not sufficient to follow the else with a
  1615. semicolon or a null clause. Instead,the NOP(no-operation)instruction can be
  1616. used for this purpose.
  1617.  
  1618.                 28
  1619.  
  1620. Example:
  1621.  
  1622. if 1 > 2 then say 'really?'
  1623.          else say 'I thought so'
  1624.  
  1625. 4-9 END
  1626.  
  1627. Usage: END [variable]
  1628. The END instruction terminates the range of a DO or SELECT instruction. If the
  1629. optional variable symbol is supplied,it is compared to the index variable of
  1630. the DO statement(which must therefore be iterative). An error is generated if
  1631. the symbols do not match,so this provides a simple mechanism for matching the
  1632. DO and END statements.
  1633. Example:
  1634.  
  1635. do i=1 to 5        /* index variable is I    */
  1636.    say i        
  1637.    end i        /* end "I" loop        */
  1638.  
  1639. 4-10 EXIT
  1640.  
  1641. Usage: EXIT [expression]
  1642. The EXIT instruction terminates the execution of a program,and is valid
  1643. anywhere within a program. The evaluated expression is passed back to the
  1644. caller as the function or command result.
  1645.  
  1646. Results Processing. The processing of the EXIT result depends on whether a
  1647. result string was requested by the calling program,and whether the current
  1648. invocation resulted from a command or function call. If a result string was
  1649. requested,the expression result is copied to a block of allocated memory and a
  1650. pointer to the block is returned as the secondary result of the call.
  1651.  
  1652. If the caller did not request a result string,and the program was invoked as a
  1653. command,then an attempt is made to convert the expression result to an
  1654. integer. This value is then returned as the primary result,with 0 as the
  1655. secondary result. This allows the EXIT expression to be interpreted as a
  1656. "return code" by the caller. Refer to Chapter 10 for further information on
  1657. the data structures used to return the result string.
  1658. Examples:
  1659.  
  1660. exit            /* no result needed    */
  1661. exit 12            /* an error return?    */
  1662.  
  1663. 4-11 IF
  1664.  
  1665. Usage: IF expression [THEN] [;] [conditional statement]
  1666. The IF instruction is used in conjunction with THEN and ELSE instruction to
  1667. conditionally execute a statement. The result of the expression must be a
  1668. boolean value. If the result is 1 (True),the statement following the THEN
  1669. symbol is executed;otherwise,control passes to the next statement(which might
  1670. be an ELSE clause.) The THEN keyword need not immediately follow the IF
  1671. expression,but may appear as a separate clause. The instruction
  1672.  
  1673.                 29
  1674.  
  1675. is actually analyzed as "IF expression; THEN; statement;." In essence,the IF
  1676. statement begins a syntactic range and establishes the test condition that
  1677. determines whether subsequent THEN or ELSE clauses will be performed.
  1678.  
  1679. Any valid statement may follow the THEN symbol;in particular,a "DO; ... END;"
  1680. group allows a series of statements to be performed conditionally.
  1681. Examples:
  1682.  
  1683. if result < 0 then exit    /* all done?   */
  1684.  
  1685. 4-12 INTERPRET
  1686.  
  1687. Usage: INTERPRET expression
  1688. The expression is evaluated and the result is executed as one or more program
  1689. statements. The statements are considered as a group,as though surrounded by a
  1690. "DO; ...;END" combination. Any statements can be included in the INTERPRETed
  1691. source,including DO or SELECT instruction.
  1692.  
  1693. An INTERPRET instruction activates a control range when it is executed,which
  1694. serves as a "fence" for LEAVE and ITERATE instructions. These instructions can
  1695. therefore be used only with DO-loops defined within the INTERPRET. The BREAK
  1696. instuction can be used to terminate the processing of INTERPRETed statements.
  1697. While it is not an error to include label clauses within the interpreted
  1698. string,only those labels defined in the original source code are searched
  1699. during a transfer of control.
  1700.  
  1701. The INTERPRET instruction can be used to solve programming problems in
  1702. interesting and novel ways. Programs can be constructed dynamically and then
  1703. executed using this instruction,or program fragments may be passed as arguments
  1704. to functions,which then INTERPRET them.
  1705. Example:
  1706.  
  1707. inst = 'say'        /* an instruction    */
  1708. interpret inst hello    /* ..."say HELLO"    */
  1709.  
  1710. 4-13 ITERATE
  1711.  
  1712. Usage: ITERATE [variable]
  1713. The ITERATE instruction terminates the current iteration of a DO instruction
  1714. and begins the next iteration. Effectively,control passes to the END statement
  1715. and then(depending on the outcome of the UNTIL expression)back to the DO
  1716. statement. The instruction normally acts on the innermost iterative DO range
  1717. containing the instruction. An error results if the LEAVE instruction is not
  1718. contained within an iterative DO instruction.
  1719.  
  1720. The optional variable symbol specifies which DO range is to be exited,in the
  1721. event that several nested ranges exist. The variable is taken as a literal and
  1722. must match the index variable of a currently active DO instruction. An error
  1723. results if no such matching DO instruction is found.
  1724.  
  1725.                 30
  1726.  
  1727. Example:
  1728.  
  1729.     do i=1 to 3
  1730.        if i=j then iterate i
  1731.        end
  1732.  
  1733. 4-14 LEAVE
  1734.  
  1735. Usage:LEAVE [variable]
  1736. LEAVE forces an immediate exit from the iterative DO range containing the
  1737. instruction. An error results if the LEAVE instruction is not contained within
  1738. an iterative DO instruction.
  1739.  
  1740. The optional variable symbol specifies which DO range is to be exited,in the
  1741. event that several nested ranges exist. The variable is taken as a literal and
  1742. must match the index variable of a currently active DO instruction. An error
  1743. results if no such matching DO instruction is found.
  1744. Example:
  1745.  
  1746.     do i=1 to limit
  1747.        if i > 5 then leave    /* maximum iterations  */
  1748.        end
  1749.  
  1750. 4-15 NOP
  1751.  
  1752. Usage: NOP
  1753. The NOP or "no-operation" instruction does just that:nothing. It is provided to
  1754. control the binding of ELSE clauses in compound IF statements.
  1755. Example:
  1756.  
  1757.     if i=j then        /* first (outer) IF    */
  1758.        if j=k then a=o    /* inner IF        */
  1759.         else nop    /* binds to inner IF    */
  1760.        else a=a+1        /* binds to outer IF    */
  1761.  
  1762. 4-16 NUMERIC
  1763.  
  1764. Usage: NUMERIC {DIGITS | FUZZ} expression
  1765.    or: NUMERIC FORM {SCIENTIFIC | ENGINEERING}
  1766. This instruction sets options relating to the numeric precision and format. The
  1767. valid forms of the NUMERIC instruction are:
  1768.  
  1769. NUMERIC DIGITS expression. Specifies the number of digits of precision for
  1770. arithmetic calculations. The expression must evaluate to a positive whole
  1771. number.
  1772.  
  1773. NUMERIC FUZZ expression. Specifies the number of digits to be ignored in
  1774. numeric comparison operations. This must be a positive whole number that is
  1775. less than the current DIGITS setting.
  1776.  
  1777. NUMERIC FORM SCIENTIFIC. Specifies that numbers that require exponential
  1778. notation be expressed in SCIENTIFIC notation. The exponent is adjusted so that
  1779. the mantissa (for non-zero) numbers) is between 1 and 10. This is the default
  1780. format.
  1781.  
  1782.                 31
  1783.  
  1784. NUMERIC FORM ENGINEERING. Selects ENGINEERING format for numbers that require
  1785. exponential notation. ENGINEERING format normalizes a number so that its
  1786. exponent is a multiple of three and the mantissa(if not 0)is between 1 and
  1787. 1000.
  1788.  
  1789. The numberic options are preserved when an internal function is called.
  1790. Examples:
  1791.  
  1792.     numeric digits 12        /* precision        */
  1793.     numeric form scientific        /* format        */
  1794.  
  1795. 4-17 OPTIONS
  1796.  
  1797. Usage: OPTIONS [FAILAT expression]
  1798.    or: OPTIONS [PROMPT expression]
  1799.    or: OPTIONS [RESULTS]
  1800. The OPTIONS instruction is used to set various internal defaults. The FAILAT
  1801. expression sets the limit at or above which command return codes will be
  1802. signalled as errors,and must evaluate to an integer value. The PROMPT
  1803. expression provides a string to be used as the prompt with the PULL (or PARSE
  1804. PULL)instruction. The RESULTS keyword indicates that the interpreter should
  1805. request a result string when it issues commands to an external host.
  1806.  
  1807. The internal options controlled by this instruction are preserved across
  1808. function calls,so an OPTIONS instruction can be issued within an internal
  1809. function without affecting the callers environment. If no keyword is specified
  1810. with the OPTIONS instuction,all controlled options revert to their default
  1811. settings.
  1812. Example:
  1813.  
  1814.     options failat 10
  1815.     options prompt "Yes Boss?"
  1816.     options results
  1817.  
  1818. 4-18 OTHERWISE
  1819.  
  1820. Usage: OTHERWISE [;] [conditional statement]
  1821. This instruction is valid only within the range of a SELECT instruction,and
  1822. must follow the "WHEN ... THEN" statements. If none of the preceding WHEN
  1823. clauses have succeeded,the statement following the OTHERWISE instruction is
  1824. executed. An OTHERWISE is not mandatory within a SELECT range. However,an error
  1825. will result if the OTHERWISE clause is omitted and none of the WHEN
  1826. instructions succeed.
  1827. Example:
  1828.  
  1829.     select
  1830.         when i=1 then say 'one'
  1831.         when i=2 then say 'two'
  1832.         otherwise say 'other'
  1833.         end
  1834.  
  1835.                 32
  1836.  
  1837. 4-19 PARSE
  1838.  
  1839. Usage: PARSE [UPPER] inputsorce [template] [,template...]
  1840. The PARSE instruction provides a mechanism to extract one or more substrings
  1841. from a string and assign them to variables. The input string can come from a
  1842. variety of sources,including argument strings,an expression,or from the
  1843. console. The template provides both the variables to be given values and the
  1844. way to determine the value strings. The template may be omitted if the
  1845. instruction is intended only to create the input string. The different options
  1846. of the instruction are described below.
  1847.  
  1848. INPUT SOURCES
  1849.  
  1850. The sources for the input strings are specified by the keyword symbols listed
  1851. below. When multiple templates are supplied,each template receives a new input
  1852. string, although for some source options the new string will be identical to
  1853. the previous one. The input source string is copied before being parsed,so the
  1854. original strings are never altered by the parsing process.
  1855.  
  1856. UPPER. This optional keyword may be used with any of the input sources,and
  1857. specifies that the input string is to be translated to uppercase before being
  1858. parsed. It must be the first token following PARSE.
  1859.  
  1860. ARG. This input option retrieves the argument strings supplied when the program
  1861. was invoked. Command invocations normally have only a single argument string,
  1862. but functions may have up to 15 argument strings. Multiple templates may be
  1863. given to retrieve successive argument strings.
  1864.  
  1865. EXTERNAL. The input strings is read from the console. If multiple templates are
  1866. supplied,each template will read a new string. This source option is the same
  1867. as PULL.
  1868.  
  1869. NUMERIC. The current numeric options are placed in a string in the order
  1870. DIGITS,FUZZ,and FORM,separated by a single space.
  1871.  
  1872. PULL. Reads a string from the input console. If multiple templates are
  1873. supplied,each template will read a new string.
  1874.  
  1875. SOURCE. The "source" string for the program is retrieved. This string is
  1876. formatted as "{COMMAND | FUNCTION} {0 | 1} called resolved ext host." The first
  1877. token indicates whether the program was invoked as a command or as a function.
  1878. The second token is a boolean flag indicating whether a result string was
  1879. requested by the caller. The called token is the name used to invoke this
  1880. program,while the resolved token is the final resolved name of the program. The
  1881. ext token is the file extension to be used for searching(the default is
  1882. "REXX"). Finally,the host token is the initial host address for commands.
  1883.  
  1884. VALUE expression WITH. The input string is the result of the supplied
  1885. expression. The WITH keyword is required to separate the expression from the
  1886. template. The expression result may be parsed repeatedly by using multiple
  1887. templates,but the expression is not reevaluated.
  1888.  
  1889. VAR variable. The value of the specified variable is used as the input string.
  1890. When multiple templates are provided,each template uses the current value of
  1891. the variable.
  1892.  
  1893.                 33
  1894.  
  1895. This value may change if the variable is included as an assignment target in
  1896. any of the templates.
  1897.  
  1898. VERSION. The current configuation of the ARexx interpreter is supplied in the
  1899. form "ARexx version cpu mpu video freq". The version toekn is the release level
  1900. of the interpreter,formatted as V1.0. The cpu token indicates the processor
  1901. currently running the program,and will be one of the values 68000,68010,or
  1902. 68020. The mpu token will be either NONE or 68881 depending on whether a math
  1903. coprocessor is available on the system. The video token will indicate either
  1904. NTSC or PAL,and the freq token gives the clock(line)frequency as either 60HZ or
  1905. 50 HZ.
  1906.  
  1907. TEMPLATES
  1908.  
  1909. Parsing is controlled by a template,which may consist of symbols,strings,
  1910. operators,and parentheses. During the parsing operation the input string is
  1911. split into substrings that are assigned to the variable symbols in the
  1912. template. The process continues until all of the variables in the template have
  1913. been assigned a value;if the input string is "used up",any remaining variables
  1914. are given null values.
  1915.  
  1916. Templates are described in depth in Chapter 8,so only a simplified description
  1917. is presented here. The goal of the parsing operation is to associate a
  1918. "current" and "next" position with each variable symbol in the template. The
  1919. substring between these positions is then assigned as the value to the
  1920. variable. There are three basic methods used to determine the value strings.
  1921.  
  1922. PARSING BY TOKENIZATION. When a variable in the template is followed
  1923. immediately by another variable,the value string is determined by breaking the
  1924. input string into words separated by blanks. Each word is assigned to a
  1925. variable in the template.
  1926.  
  1927. Values determined by tokenization will never have leading or trailing blanks.
  1928. Normally the last variable in the template receives the untokenized remainder
  1929. of the input string,since it is not followed by a symbol. A "placeholder"
  1930. symbol,signified by a period(.),may be used to force tokenization. Placeholders
  1931. behave like variables in the template except that they are never actually
  1932. assigned a value.
  1933. Example:
  1934.  
  1935.     /* Numeric string is: "9 0 SCIENTIFIC"    */
  1936.     parse numberic digits fuzz form .
  1937.     say digits        /* =>9            */
  1938.     say fuzz        /* =>0            */
  1939.     say from        /*=> SCEIENTIFIC    */
  1940.  
  1941. PARSING BY POSITION. If the fields in the input string have known positions,
  1942. value strings can be specified by absolute or relative positions. Relative
  1943. positions are indicated by a number preceded by a "+" or "-" operator. Each
  1944. positional marker updates the scan position in the string. The value assigned
  1945. to a variable is the string from the current position up to,but not including,
  1946. the next position in the string.
  1947.  
  1948.                 34
  1949.  
  1950. Example:
  1951.  
  1952.     /* assume argument is "1234567890"        */
  1953.     parse arg 1 a 3 b +2 1 c
  1954.     say a b c         /* ==> 12 34 1234567890    */
  1955.  
  1956. PARSING WITH PATTERNS. Fields in the input string separated by specific
  1957. characters or strings can be parsed using a pattern,which is matched against
  1958. the input string. A pattern is specified in the template as a string token,or
  1959. alternatively as a symbol enclosed in parentheses. The position in the parse
  1960. string matched by the pattern determines the value strings. The pattern is
  1961. removed from the input string when a match is found;this is the only parsing
  1962. operation that modifies the input string.
  1963. Example:
  1964.  
  1965.     check = 'one,two,three'
  1966.     parse var check a ',' b ',' c
  1967.     say a b c    /* ==> one two three    */
  1968.  
  1969. 4-20 PROCEDURE
  1970.  
  1971. Usage:PROCEDURE [EXPOSE variable [variable...]]
  1972. The PROCEDURE instruction is used within an internal function to create a new
  1973. symbol table. This protects the symbols defined in the caller's environment
  1974. from being altered by the execution of the function. PROCEDURE is usually the
  1975. first statement within the function,although it is valid anywhere withing the
  1976. function body. It is an error to execute two PROCEDURE statements within the
  1977. function.
  1978.  
  1979. EXPOSING VARIABLES. The EXPOSE subkeyword provides a selective mechanism for
  1980. accessing the caller's symbol table,and for passing global variables to a
  1981. function. The variables following the EXPOSE keyword are taken to refer to
  1982. symbols in the caller's table. Any subsequent changes made to these variables
  1983. will be reflected in the caller's environment.
  1984.  
  1985. The variables in the EXPOSE list may include stems or compound symbols,in which
  1986. case the ordering of the variables becomes significant. The EXPOSE list is
  1987. processed from left to right,and compound symbols are expanded based on the
  1988. values in effect in the new generation. For example,suppose that the value of
  1989. the symbol J in the previous gneration is 123,and that J is unitialized in the
  1990. new generation. Then PROCEDURE EXPOSE J A.J will expose J and A.123,whereas
  1991. PROCEDURE EXPOSE A.J J will expose A. J. and J. Exposing a stem has the effect
  1992. of exposing all possible compound symbols derived from that stem.
  1993. Example:
  1994.  
  1995.     fact: procedure        /* a recursive function    */
  1996.        arg i
  1997.        if i <=1
  1998.           then return 1
  1999.           else return i*fact(i-1)
  2000.  
  2001.                 35
  2002.  
  2003. Usage:PULL [template] [,template...]
  2004. This is a shorthand form of the PARSE UPPER PULL instruction. It reads a string
  2005. from the input console,translates it to uppercase,and parses it using the
  2006. template. Multiple strings can be ready by supplying additional templates. The
  2007. instruction will read from the console even if no template is given.
  2008.  
  2009. Templates are described briefly with the PARSE instruction and in greater depth
  2010. in Chapter 8.
  2011. Example:
  2012.  
  2013.     pull first last.    /* read names        */
  2014.  
  2015. 4-22 PUSH
  2016.  
  2017. Usage: PUSH [expression]
  2018. The PUSH instruction is used to prepare a stream of data to be ready by a
  2019. command shell or other program. It appends a "newline" to the result of the
  2020. expression and then stacks or "pushes" it into the STDIN stream. Stacked lines
  2021. are placed in the stream in "last-in, first-out" order,and are then available
  2022. to be ready just as though they had been entered interactively. For example,
  2023. after issuing the instructions
  2024.  
  2025.     push line 1
  2026.     push line 2
  2027.     push line 3
  2028.  
  2029. the steam would be read in the order "line 3," "line 2" and "line 1."
  2030.  
  2031. There are several restrictions governing the use of the PUSH instruction and
  2032. its alter ego QUEUE. These instructions use a special I/O mechanism to
  2033. accomplish their task,and as a result can be used only with an interactive
  2034. (stream-model) I/O device like a console or pipe. The stream must be managed by
  2035. with a DOS handler that supports the special ACTION_STACK (for PUSH) or
  2036. ACTION_QUEUE (for QUEUE) command.
  2037.  
  2038. PUSH allows the STDIN stream to be used as a private scratchpad to prepare data
  2039. for subsequent processing. For example,several files could be concatenated with
  2040. delimiters between them by simply reading the input files,PUSHing the lines
  2041. into the stream,and inserting a delimiter where required. Once the stacked
  2042. lines are exhausted,the stream reverts to its normal source of data.
  2043. Example:
  2044.  
  2045.     /* Stack commands for compile and link*/
  2046.     push "blink c.o+main.o library amiga.lib to myprog"
  2047.     push "cc main"
  2048.  
  2049.                 36
  2050.  
  2051. 4-23 QUEUE
  2052.  
  2053. Usage:QUEUE [expression]
  2054. The QUEUE instruction is used to prepare a stream of data to be read by a
  2055. command shell or other program. It is very similar to the preceding PUSH
  2056. instruction,and differs only that the data lines are placed in the STDIN stream
  2057. in "first-in,first-out" order. In this case the instruction
  2058.  
  2059.     queue line 1
  2060.     queue line 2
  2061.     queue line 3
  2062.  
  2063. would be read in the order "line 1," "line 2," and "line 3." The QUEUEd lines
  2064. always precede all interactivly-entered lines,and always follow any PUSHed
  2065. (stacked)lines.
  2066.  
  2067. The same restriction noted with the use of the PUSH instruction apply to the
  2068. QUEUE instruction. The queueing mechanism uses the ACTION_QUEUE command,so the
  2069. DOS handler associated with the STDIN stream must support this command.
  2070.  
  2071. In most cases the choice of whether to use PUSH or QUEUE is just a matter of
  2072. convenience or personal preference. Each of them provides a "scratch pad"
  2073. facility similar to that provided by an I/O pipe,but useful within one program
  2074. or task rather than just for interprocess communications.
  2075. Example:
  2076.  
  2077.     /* Queue commands for compile and link */
  2078.     queue "cc main"
  2079.     queue "blink c.o+main.o library amiga.lib to myprog"
  2080.  
  2081. 4-24 RETURN
  2082. RETURN is used to leave a function and return control to the point of the
  2083. previous function invocation. The evaluated expression is returned as the
  2084. function result. If an expression is not supplied,an error may result in the
  2085. caller's environment. Functions called from within an expression must return a
  2086. result string,and will generate an error if no result is available. Function
  2087. invoked by the CALL instruction need not return a result.
  2088.  
  2089. A RETURN issued from the base environment of a program is not an error,and is
  2090. equivalent to an EXIT instruction. Refer to the EXIT instruction for a
  2091. description of how result strings are passed back to an external caller.
  2092. Example:
  2093.  
  2094.     return 6*7        /*the answer    */
  2095.  
  2096.                 37
  2097.  
  2098. 4-25 SAY
  2099.  
  2100. Usage:SAY [expression]
  2101. The result of the evaluated expression is written to the output console,with a
  2102. "newline" character appended. If the expression is omitted,a null string is
  2103. sent to the console.
  2104. Example:
  2105.  
  2106.     say 'The anwer is ' value
  2107.  
  2108. 4-26 SELECT
  2109.  
  2110. Usage:SELECT
  2111. This instruction begins a group of instructions containing one or more WHEN
  2112. clauses and possibly a single OTHERWISE clause,each followed by a conditional
  2113. statement.
  2114.  
  2115. Only one of the conditional statements within the SELECT group will be
  2116. executed. Each WHEN statement is executed in succession until one succeeds;if
  2117. none succeeds,the OTHERWISE statement is executed. The SELECT range must be
  2118. terminated by an eventual END statement.
  2119. Example:
  2120.  
  2121.     select
  2122.         when i=1 then say 'one'
  2123.         when i=2 then say 'two'
  2124.         otherwise say 'other'
  2125.         end
  2126.  
  2127. 4-27 SHELL
  2128.  
  2129. Usage:SHELL [symbol | string] [expression]
  2130. The SHELL instruction is a synonym for the ADDRESS instruction.
  2131. Example:
  2132.  
  2133.     shell edit    /* set host to 'EDIT'    */
  2134.  
  2135. 4-28 SIGNAL
  2136.  
  2137. Usage: SIGNAL {ON |OFF} condition
  2138.    or: SIGNAL [VALUE] expression
  2139. There are two forms of the SIGNAL instruction. The first form illustrated
  2140. controls the state of the internal interrupt flags. Interrupts allow a program
  2141. to detect and retain control when certain errors occur,and are discussed in
  2142. Chapter 7. In this form SIGNAL must be followed by one of the keywords ON or
  2143. OFF and one of the condition keywords listed below. The interrupt flag
  2144. specified by the condition symbol is then set to the indicated state. The valid
  2145. signal conditions are:
  2146.  
  2147. BREAK_C  A "control-C" break was detected.
  2148. BREAK_D  A "control-D" break was detected.
  2149. BREAK_E  A "control-E" break was detected.
  2150.  
  2151.                 38
  2152.  
  2153. BREAK_F A "control-F" break was detected.
  2154. ERROR A Host command returned a non-zero code.
  2155. HALT  An external HALT request was detected.
  2156. IOERR An error was detected by the I/O system.
  2157. NOVALUE An uninitialized variable was used.
  2158. SYNTAX  A syntax or execution error was detected.
  2159.  
  2160. The condition keywords are interpreted as labels to which control will
  2161. transferred if the selected condition occurs. For example,if the ERROR
  2162. interrupt is enabled and a command returns a non-zero code,the interpreter will
  2163. transfer control to the label ERROR:. The condition label must of course be
  2164. defined in the program;otherwise,an immediate SYNTAX error results and the
  2165. program exits.
  2166.  
  2167. In the second form of the instruction,the tokens following SIGNAL are evaluated
  2168. as an expression. An immediate interrupt is generated that transfers control to
  2169. the label specified by the expression result. The instruction thus acts as a
  2170. "computed goto."
  2171.  
  2172. INTERRUPTS. Whenever an interrupt occurs,all currently active control ranges
  2173. (IF,DO,SELECT,INTERPRET,or interactive TRACE) are dismantled before the
  2174. transfer of control. Thus,the transfer cannot be used to jump into the range of
  2175. a DO-loop or other control structure. Only the control structures in the
  2176. current environment are affected by a SIGNAL condition,so it is safe to SIGNAL
  2177. from within an internal function without affecting the state of the caller's
  2178. environment.
  2179.  
  2180. SPECIAL VARIABLES. The special variable SIGL is set to the current line number
  2181. whenever a transfer of control occurs. The program can inspect SIGL to
  2182. determine which line was being executed before the transfer. If an ERROR or
  2183. SYNTAX condition causes an interrupt,the special variable RC is set to the
  2184. error code that triggered the interrupt. For the ERROR condition,this code is
  2185. usually an error secerity level. The SYNTAX condition will always indicate an
  2186. ARexx error code.
  2187. Examples:
  2188.  
  2189.     signal on error        /* enable interrupt    */
  2190.     signal off syntax    /* disable SYNTAX    */
  2191.     signal start        /* goto START        */
  2192.  
  2193. 4-29 THEN
  2194.  
  2195. Usage:THEN[;] [conditional statement]
  2196. The THEN instruction must be the next statement following an IF or WHEN
  2197. instruction,and is valid only in that context. It tests whether the preceding
  2198. expression evaluated to 1(True),in which case the conditional statement
  2199. following the THEN is performed. If the expression result was a 0(False),the
  2200. conditional statement is skipped.
  2201.  
  2202.                 39
  2203.  
  2204. Example:
  2205.  
  2206.     if i=j
  2207.        then say 'equal'
  2208.        else say 'not equal'
  2209.  
  2210. 4-30 TRACE
  2211.  
  2212. Usage:TRACE [symbol|string|[[VALUE] expression]]
  2213. The TRACE instruction is used to set the internal tracing mode. If a symbol or
  2214. string is supplied,it is taken as a literal. Otherwise,the tokens following the
  2215. VALUE keyword are evaluated as an expression. The VALUE keyword can be omitted
  2216. if the expression doesn't start with a symbol or string token.
  2217.  
  2218. In either case the result string is converted to uppercase and checked first
  2219. for one of the "alphabetic" options. The valid alphabetic options are ALL,
  2220. COMMANDS,ERRORS,INTERMEDIATES,LABELS,RESULTS,and SCAN. These can be spelled out
  2221. in full or shortened to the initial character,and are described in Chapter 7.
  2222. If the result doesn't match any of these options,the interpreter attempts to
  2223. convert it to an integer. A conversion failure here will be reported as an
  2224. error.
  2225.  
  2226. PREFIX CHARACTERS. Two special symbol characters may precede any of the
  2227. alphabetic keywords. The "?" character interactive tracing,and the "!"
  2228. character controls command inhibition. These characters act as "toggles" to
  2229. alternatively select and de-select the respective modes. Any number of prefix
  2230. characters may precede an alphabetic option. Interactive tracing and command
  2231. inhibition are described in Chapter 7.
  2232.  
  2233. NUMERIC OPTION. If the specified trace option is a negative whole number,it is
  2234. accepted as a trace suppression count. The suppression count is the number of
  2235. clauses(that would otherwise be traced)to be passed over before resuming the
  2236. tracing display. Suppression counts are ignored execept during interactive
  2237. tracing.
  2238. Examples:
  2239.  
  2240.     trace ?r        /* interactive RESULTS    */
  2241.     trace off
  2242.     trace -20        /* skip 20 clauses    */
  2243.  
  2244. 4-31 UPPER
  2245.  
  2246. Usage:UPPER variable [variable...]
  2247. The values of the variables in the list are converted to uppercase. It is not
  2248. an error to include an uninitialized variable in the list,but it will be
  2249. trapped if the NOVALUE interrupt has been enabled.
  2250.  
  2251. The TRANSLATE() or UPPER() Built-In functions could also be used to convert
  2252. variables to uppercase,but the instruction form is more concise(and faster) if
  2253. several variables are being converted.
  2254.  
  2255.                 40
  2256.  
  2257. Example:
  2258.  
  2259.     when='Now is the time'
  2260.     upper when
  2261.     say when        /* NOW IS THE TIME    */
  2262.  
  2263. 4-32 WHEN
  2264.  
  2265. Usage:WHEN expression [THEN [;] [conditional statement]]
  2266. The WHEN instruction is similar to the IF instruction,but is valid only within
  2267. a SELECT range. Each WHEN expression is evaluated in turn and must result in a
  2268. boolean value. If the result is a 1,the conditional statement is executed and
  2269. control passes to the END statement that terminates the SELECT. As in the case
  2270. of the IF instruction,the THEN need not be part of the same clause.
  2271. Example:
  2272.  
  2273.     select;
  2274.        when i<j thn say 'less'
  2275.        when i=j then say 'equal'
  2276.        otherwise     say 'greater'
  2277.        end
  2278.  
  2279.                 41
  2280.  
  2281.                           CHAPTER 5  COMMANDS
  2282.  
  2283. The REXX language is unusual in that an entire syntactic class of program
  2284. statements are reserved for cmmands,statements that have meaning not within the
  2285. language itself but rather to an external program. When a command clause is
  2286. found in a program,it is evaluated as an expression and then sent through the
  2287. command interface to an explicit or implicit host application,an external
  2288. program that has announced its ability to receive commands. The host
  2289. application then processes the command and returns a result code that indicates
  2290. whether the command was performed successfully. In this manner every host
  2291. program becomes fully programmable,and with even a limited set of predefined
  2292. operations can be customized by the end user.
  2293.  
  2294. This chapter discusses the ARexx command interface and examines some of the
  2295. ways in which commands can be used to build programs for an external program.
  2296. Such programs are ofter called "macro programs" because they implement a
  2297. complex ("macro") action from a series of simpler "micro" commands.
  2298.  
  2299. Chapter 10 has detailed information on the data structers required to implement
  2300. a command interface for an applications program.
  2301.  
  2302. 5-1 COMMAND CLAUSES
  2303.  
  2304. Syntactically,a command clause is just an expression that can't be classified
  2305. as another type of clause. The actual structure of the command is dictated by
  2306. the external host to which it is intended,but in most cases will follow the
  2307. model of a name or letter followed by parameter data. Command names can be
  2308. given as either a symbol or a string. However,it is generally safer to use a
  2309. string for the name,since it can't be assigned a value or be mistaken for an
  2310. instruction keyword. For example,the following might be commands for a text
  2311. editor:
  2312.  
  2313.     JUMP current+10        /* advance to next    */
  2314.     'insert' newstring    /* blast it in        */
  2315.     'TOP'            /* back to the top    */
  2316.  
  2317. Since command clauses are expressions,they are fully evaluated before being
  2318. sent to the host. Any part of the final command string can be computed within
  2319. the program,so virtually any sort of command structure can be created.
  2320.  
  2321. The interpretation of the received commands depends entirely on the host
  2322. application. In the simplest case the command strings will correspond exactly
  2323. to commands that could be entered directly by a user. For instance,positional
  2324. control(up/down)commands for a text editor would probably have identical
  2325. interpretations whether issued by the user or from a program. Other commands
  2326. may be valid only when issued from a macro program;a command to simulate a menu
  2327. operation would probably not be entered by the user.
  2328.  
  2329.                 43
  2330.  
  2331. 5-2 THE HOST ADDRESS
  2332.  
  2333. The destination for a command is determined by the current host address,which
  2334. is the name of the public message port managed by an external program. ARexx
  2335. maintains two implicit host addresses,a "current" and a "previous" value,as
  2336. part of the program's storage environment. These values can be changed at any
  2337. time using the ADDRESS instruction(or its synonym,SHELL,)and the current host
  2338. address can be inspected with the ADDRESS()Built-In fuction. The default host
  2339. address string is "REXX",but this can be overridden when a program is invoked.
  2340. In particular,most host applications will supply the name of their public port
  2341. when they invoke a macro program,so that the macro can automatically issue
  2342. commands back to the host.
  2343.  
  2344. One special host address is recognized: the string COMMAND indicates that the
  2345. command should be issued directly to the underlying DOS. All other host
  2346. addresses are assumed to refer to a public message port. An attempt to send a
  2347. commmand to a non-existent message port will generate the syntax error "Host
  2348. environment not found."
  2349.  
  2350. Single commands can be sent to a specific host without disturbing the host
  2351. address settings. This is done using the ADDRESS instruction,as the following
  2352. example illustrates:
  2353.  
  2354. ADDRESS MYEDIT 'jump top'
  2355.  
  2356. This example would send the command "jump top" to an external host named
  2357. "MYEDIT."
  2358.  
  2359. It is important to note that you cannot send commands to a host application
  2360. without knowing the name of its public message port. Writing macro programs to
  2361. communicate with two or more hosts may require some clever programming to
  2362. determine whether both hosts are active and what their respective host
  2363. addresses are.
  2364.  
  2365. 5-3 THE COMMAND INTERFACE
  2366.  
  2367. ARexx implements its command interface using the message-passing facilities
  2368. provided by the EXEC operating system. Each host application must provide a
  2369. public message port,the name of which is referred to as the host address. ARexx
  2370. programs issue commands by placing the command string in a message packet and
  2371. sending the packet to the host's message port. The program "sleeps" while the
  2372. host processes the command,and awakens when the message packet returns. The
  2373. entire process can be regarded as a dialogue between the host application and a
  2374. macro program:the host initiates the dialogue by invoking the macro,and the
  2375. macro program replies with one or more command strings. The commands that can
  2376. be sent are not limited to simple text strings,but might be address pointers or
  2377. even bit-mapped images.
  2378.  
  2379. After it finishes processing a command,the host "replies" the message packet
  2380. with a return code that indicates the status of the command. This return code
  2381. is placed in the ARexx special variable RC so that it can be examined by the
  2382. program. A value of zero is assumed to mean that no errors occurred,while
  2383. positive values usually indicate progressively more severe error conditions.
  2384. The return code allows the macro program to determine whether the command
  2385. succeeded and to take action if it failed,so it is important for each
  2386. applictions program to document the meanings of the return codes for its
  2387. commands.
  2388.  
  2389.                 44
  2390.  
  2391. 5-4 USING COMMANDS IN MACRO PROGRAMS
  2392.  
  2393. ARexx can be used to write programs for any host application that includes a
  2394. suitable command interface. Some applications programs are designed with an
  2395. embedded macro language,and may include many predefined macro commands. With a
  2396. well-designed macro language interface the user will be usually unaware of
  2397. whether a given action is implemented as a primitive operations or as a macro
  2398. program.
  2399.  
  2400. The starting point in designing a macro program is to examine the commands that
  2401. would be required to perform it manually. The documentation for the host
  2402. application program should then describe the possible return codes for each
  2403. command;these codes can be used to determine whether the operation performed by
  2404. the command was successful. Check also for "shortcut" commands that may be
  2405. available only to macro programs;some applications programs may include very
  2406. powerful functions that were implemented specifically for use in macro
  2407. programs.
  2408.  
  2409. 5-5 USING AREXX WITH COMMAND SHELLS
  2410.  
  2411. Although ARexx was designed to work most effectively with programs that support
  2412. its specific command interface,it can be used with any "command shell" program
  2413. that uses standards I/O mechanisms to obtain its input stream. There are
  2414. several ways to use ARexx to prepare a stream of commands for such program.
  2415.  
  2416. One obvious technique is to create an actual command file on the "RAM:" disk
  2417. and then pass it directly to the command shell. For example,you could open a
  2418. new CLI window to run a standard "execute" script using the following short
  2419. program:
  2420.  
  2421.     /* Launch a new CLI    */
  2422.     address command
  2423.     conwindow = "CON:0/0/640/100/NewOne"
  2424.  
  2425.     /* create a command file on the fly  */
  2426.     call open out,"ram:$$temp",write
  2427.     call writeln out,'echo "this is a test"'
  2428.     call close out
  2429.  
  2430.     /* open the new CLI window */
  2431.     'newcli' conwindow "ram:$$temp"'
  2432.     exit
  2433.  
  2434. Since no disk accesses are required,this method is actually fairly fast,if not
  2435. very elegant.
  2436.  
  2437. Another alternative is to use the command stacking facility provided by the
  2438. PUSH and QUEUE instructions. These instructions allow an ARexx program to stack
  2439. an arbitrary stream of commands and data for the command shell or other program
  2440. to read. Any set of commands that could be "typed ahead" at a command prompt
  2441. can be prepared in this fashion. After the ARexx program exits,the next program
  2442. that uses the input stream will read the prepared commands and can process them
  2443. in the normal fashion.
  2444.  
  2445.                 45
  2446.  
  2447. 5-6 COMMAND INHIBITION
  2448.  
  2449. Sometimes it is necessary to write and test macro programs that issue
  2450. potentially destructive commands. For instance,a program to find and delete
  2451. unneeded files would be difficult to test safely,since it might accidentally
  2452. delete the wrong files and would require a continual source of new files for
  2453. testing.
  2454.  
  2455. To simply the development and testing of such programs,ARexx provides a special
  2456. tracing mode called command inhibition that suppresses host commands. While in
  2457. command inhibition mode,command processing proceeds normally except that the
  2458. command is not actually issued and the variable RC is set to 0. This allows the
  2459. program logic to be verified before any commands are actually sent to the
  2460. external program. Chapter 7 has further information on this facility.
  2461.  
  2462.                 46
  2463.  
  2464.                            CHAPTER 6  FUNCTIONS
  2465.  
  2466. The basic concept of a function is a program or group of statements that will
  2467. be executed whenever the function name appears in a certain context. Functions
  2468. are an important building block of most computer languages in that they allow
  2469. modular programming -- the ability to build a large program from a series of
  2470. smaller,more easily developed modules. In ARexx a function may be defined as
  2471. part of(internal to)a program,as part of a library,or as a separate external
  2472. program.
  2473.  
  2474. 6-1 SYNTAX AND SEARCH ORDER
  2475.  
  2476. Function calls in an expression are defined syntactically as a symbol or string
  2477. followed immediately by an open parenthesis. The symbol or string(taken an a
  2478. literal)specifies the function name,and the open parenthesis begins the
  2479. argument list. Between the opening and eventual closing parentheses are zero or
  2480. more argument expressions,separated by commas,that supply the data being passed
  2481. to the function. For example,
  2482.  
  2483.     CENTER('title",20)
  2484.     ADDRESS()
  2485.     'AllocMem'(256*4,1)
  2486.  
  2487. are all valid function calls. Each argument expression is evaluated in turn and
  2488. the resulting strings are passed as the argument list to the function. There is
  2489. no limit to the number of arguments that may be passed to an internal
  2490. function,but calls to Built-In or external functions are limited to a maximum
  2491. of 15 arguments. Note that each argument expression,while ofter just a single
  2492. literal value,can include arithmetic or string operations or even other
  2493. function calls. Argument expressions are evaluated from left to right.
  2494.  
  2495. Functions can also be invoked using the CALL instruction. The syntax of this
  2496. form is slightly different,and is described in Chapter 4. The CALL instruction
  2497. can be used to invoke a function that may not return a value.
  2498.  
  2499. SEARCH ORDER
  2500.  
  2501. Function linkages in ARexx are established dynamically at the time of the
  2502. function call. A specific search order is followed until a function matching
  2503. the name symbol or string is found. If the specified function cannot be
  2504. located, an error is generated and the expression evaluation is terminated. The
  2505. full search order is:
  2506.  
  2507. 1. Internal Functions. The program source is examined for a label that matches
  2508. the function name. If a match is found,a new storage environment is created and
  2509. control is transferred to the label.
  2510.  
  2511. 2. Built-In Functions. The Build-In function library is searched for the
  2512. specified name. All of these functions are defined by uppercase names,and the
  2513. library has been specially organized to make the search as efficient as
  2514. possible.
  2515.  
  2516.                 47
  2517.  
  2518. 3. Function Libraries and Function Hosts. The available function libraries and
  2519. function hosts are maintained in a prioritized list,which is searched starting
  2520. at the highest priority until the requested function is found or the end of the
  2521. list is reached. Each function library is opened and called at a special entry
  2522. point to determine whether it contains a function matching the given name.
  2523. Function hosts are called using a message-passing protocol similar to that used
  2524. for commands,and may be used as gateways for remote procedure calls to other
  2525. machines in a network.
  2526.  
  2527. 4. External ARexx Programs. The final search step is to check for an external
  2528. ARexx program file by sending an invocation message to the ARexx resident
  2529. process. The search always begins in the current directory,and follows the same
  2530. search path as the original ARexx program invocation. The name matching process
  2531. is not case-sensitive.
  2532.  
  2533. Note that the function name-matching procedure may be case-sensitive for some
  2534. of the search steps but not for others. The matching procedure used in a
  2535. function library or function host is left to the discretion of the applications
  2536. designer. Functions defined with mixed-case names must be called using a string
  2537. token,since symbol names are always translated to uppercase.
  2538.  
  2539. The full search order is followed whenever the function name is defined by a
  2540. symbol token. However,the search for internal functions is bypassed if the name
  2541. is specified by a string token. This allows internal functions to usurp the
  2542. names of external functions,as in the following example:
  2543.  
  2544. CENTER:                /* internal "CENTER" */
  2545. arg string,length        /* get arguments     */
  2546. length = min(length,60)        /* compute length    */
  2547. return 'CENTER'(string,length)
  2548.  
  2549. Here the Built-In fuction CENTER()has been replaced by an internal function of
  2550. the same name,which calls the original function after modifying the length
  2551. argument.
  2552.  
  2553. INTERNAL FUNCTIONS
  2554.  
  2555. The interpreter creates a new storage environment when an internal function is
  2556. called,so that the previous(caller's)environment is preserved. The new
  2557. environment inherits the values from its predecessor,but subsequent changes to
  2558. the environment variables do not affect the previous environment. The specific
  2559. values that are preserved are:
  2560.  
  2561. The current and previous host addresses,
  2562. The NUMERIC DIGITS,FUZZ,and FORM settings,
  2563. The trace option,inhibit flag,and interace flag,
  2564. The state of the interrupt flags defined by the SIGNAL instruction,and
  2565. The current prompt string as set by the OPTIONS PROMPT instruction.
  2566.  
  2567. The new environment does not automatically get a new symbol table,so initially
  2568. all of the variables in the previous environment are available to the called
  2569. function. The PROCEDURE instruction can be used to create a new symbol table
  2570.  
  2571.                 48
  2572.  
  2573. and thereby protect the caller's symbol values.
  2574.  
  2575. Execution of the internal function proceeds until a RETURN instruction is
  2576. executed. At this point the new environment is dismantled and control resumes
  2577. at the point of the function call. The expression supplied with the RETURN
  2578. instruction is evaluated and passed back to the caller as the fuction result.
  2579.  
  2580. BUILT-IN FUNCTIONS
  2581.  
  2582. ARexx provides a substantial library of predefined functions as part of the
  2583. language system. These functions are always available and have been optimized
  2584. to work with the internal data structures. In general the Built-In functions
  2585. execute much faster than an equivalent interpreted function,so their usage is
  2586. strongly recommended.
  2587.  
  2588. The Built-In Function Library is not user-extensible,but additional functions
  2589. will be included in later releases.
  2590.  
  2591. EXTERNAL FUNCTION LIBRARIES
  2592.  
  2593. External function libraries provide a mechanism with which users and
  2594. applications developers can extend the functionality of ARexx. A function
  2595. library is a collection of one or more functions together with a "query" entry
  2596. point that serves to match a name string with the appropriate function.
  2597. External function libraries are supported as standard Amiga shared libraries,
  2598. and may be either memory or disk-resident. Disk-resident libraries are loaded
  2599. and opened as needed.
  2600.  
  2601. The ARexx resident process maintains a list,called the Library List,of the
  2602. currently available function libraries and function hosts. Applications
  2603. programs can add or remove function libraries as required. The Library List is
  2604. maintained as a priority-sorted queue,and entries can be added at an
  2605. appropriate priority to control the function name resolution. Libraries with
  2606. higher priorities are searched first;within a given priority level,those
  2607. libraries added first are searched first.
  2608.  
  2609. During the search process the ARexx interpreter opens each library and calls
  2610. its "query" entry point. The query function must then check to see whether the
  2611. requested function name is in the library. If not,it returns a "function not
  2612. found" error code and the search continues with the next library in the list.
  2613. Function libraries are always closed after being checked so that the operatiing
  2614. system can reclaim the memory space if required. Once the requested function
  2615. has been found,it is called with the arguments passed by the interpreter,and
  2616. must return an error code and a result string.
  2617.  
  2618. The ARexx language system includes an external function library in a file
  2619. called "rexxsupport.library". It contains a number of Amiga-specific functions
  2620. and is described in Appendix D. Chapter 10 provides information on designing
  2621. and implementing function libraries.
  2622.  
  2623.                 49
  2624.  
  2625. FUNCTION HOSTS
  2626.  
  2627. Function hosts are called by sending a function invocation message packet to
  2628. the public message port identified by the host's name. No constraints are
  2629. imposed on the iternal design of the host except that it must eventually return
  2630. the invocation message with an appropriate return code and result string. The
  2631. function call may result in a new program being loaded and run,or might even be
  2632. sent to a network handler as a remote procedure call.
  2633.  
  2634. The available function hosts,along with the function libraries,are contained in
  2635. the Library List maintained by the resident process. This list provides a
  2636. general mechanism for resolving function names in a priority-controlled manner.
  2637.  
  2638. The ARexx resident process is an example of a function host. It is added to the
  2639. Library List at a nominal priority of -60 when the resident process is started,
  2640. using the same name ("REXX")that is used for command invocations. When it
  2641. receives a function invocation packet,it searches for an external file matching
  2642. the function name,just as it would for a command invocation of the same name.
  2643. In particular,the search begins with the current directory and process is not
  2644. case-sensitive,but is affected by the presence of explicit directory
  2645. specifications or file extensions in the name string. The rules governing the
  2646. search for external programs are covered in Chapter 9.
  2647.  
  2648. External programs are always run as a separate process in the Amiga's
  2649. multitasking system. The calling program "sleeps" until the called function
  2650. finishes and the message packet returns. The result string and error code are
  2651. returned in the packet.
  2652.  
  2653. 6-2 THE BUILT-IN FUNCTION LIBRARY
  2654.  
  2655. This section of the chapter is devoted to descriptions of the individual Built
  2656. In functions,which are listed alphabetically. Many of the functions have
  2657. optional as well as required arguments. The optional arguments are shown in
  2658. brackets,and generally have a default value that is used if the argument is
  2659. omitted.
  2660.  
  2661. MAXIMUM ARGUMENTS. While internal functions can be called with any number of
  2662. arguments,the Built-In functions(and external functions as well)are limited to
  2663. a maximum of 15 arguments.
  2664.  
  2665. PAD AND OPTION CHARACTERS. For functions that accept a "pad" character
  2666. argument,only the first character of the argument string is significant. If a
  2667. null string is supplied,the default padding character(usually a blank)will be
  2668. used. Similarly,where an option keyword is specified as an argument,only the
  2669. first character is significant. Option keywords may be given in uppercase or
  2670. lowercase.
  2671.  
  2672. I/O SUPPORT FUNCTIONS. ARexx provides functions for creating and manipulating
  2673. external DOS files. The functions available at the present time are OPEN(),
  2674. CLOSE(),READCH(),READLN(),WRITECH(),WRITELN(),EOF(),SEEK(),and EXISTS(). Files
  2675. are referenced by a "logical name," a case-sensitive name that is assigned to a
  2676. file when it is first opened.
  2677.  
  2678.                 50
  2679.  
  2680. There is no limit to the number of files that may be open simultaneously,and
  2681. all open files are closed automatically when the program exits.
  2682.  
  2683. BIT-MANIPULATION FUNCTIONS. The functions BITCHG(),BITCLR(),BITCOMP(),BITSET(),
  2684. and BITTST() are provided to implement extended bit-testing on character
  2685. strings. These functions differ from similar string-manipulation functions in
  2686. that the elementary unit of comparison is the bit rather than the byte. Bit
  2687. number are defined such that bit 0 is the low-order bit of the rightmost byte
  2688. of the string.
  2689.  
  2690. ABBREV()
  2691.  
  2692. Usage:ABBREV(string1,string2,[length]
  2693. Returns a boolean value that indicates whether string2 is an abbreviation of
  2694. string1 with length greater than or equal to the specified length argument. The
  2695. default length is 0,so the null string is an acceptable abbreviation.
  2696. Example:
  2697.  
  2698.     say abbrev('fullname','ful'  ==>1
  2699.     say abbrev('almost','alm',4) ==>0
  2700.     say abbrev('any','')         ==>1
  2701.  
  2702. ABS()
  2703.  
  2704. Usage:ABS(number)
  2705. Returns the absolute value of the number argument,which must be numeric.
  2706. Examples:
  2707.  
  2708.     say abs(-5.35)            ==>5.35
  2709.     say abs(10)            ==>10
  2710.  
  2711. ADDLIB()
  2712.  
  2713. Usage ADDLIB(name,priority,[offset,version])
  2714. Adds a function library or a function host to the Library List maintained by
  2715. the resident process. The name argument specifies either the name of a function
  2716. library or the public message port associated with a function host. The name is
  2717. case-sensitive,and any libraries thus declared should reside in the system
  2718. LIBS: directory. The priority argument specifies the search priority and must
  2719. be an integer between 100 and -100,inclusive. The offset and version arguments
  2720. apply only to libraries. The offset is the integer offset to the library's
  2721. "query" entry point,and the version is an integer specifying the minimum
  2722. acceptable release level of the library.
  2723.  
  2724. The function returns a boolean result that indicates whether the operation was
  2725. successful. Note that if a library is specified,it is not actually opened at
  2726. this time;similarly,no check is performed as to whether a specified function
  2727. host port has been opened yet.
  2728. Example:
  2729.  
  2730.     say addlib("rexxsupport.library",0,-30,0)==>1
  2731.     call addlib "EtherNet",-20    /* a gateway */
  2732.  
  2733.                 51
  2734.  
  2735. ADDRESS()
  2736.  
  2737. Usage:ADDRESS()
  2738. Returns the current host address string. The host address is the message port
  2739. to which commands will be sent. The SHOW()function can be used to check whether
  2740. the required external host is actually available.
  2741. See Also:SHOW()
  2742. Example:
  2743.  
  2744.     say address()        ==>REXX
  2745.  
  2746. ARG()
  2747.  
  2748. Usage:ARG([number],['Exists' | 'Omitted'])
  2749. ARG()returns the number of arguments supplied to the current environment. If
  2750. the number parameter alone is supplied,the corresponding argument string is
  2751. returned. If a number and one of the keywords Exists or Omitted is given,the
  2752. boolean return indicates the status of the corresponding argument. Note that
  2753. the existence or omission test does not indicate whether the string has a null
  2754. value,but only whether a string was supplied.
  2755. Examples:
  2756.  
  2757.     /* Assume arguments were: ('one,,10)        */
  2758.     say arg()            ==>3
  2759.     say arg(1)            ==>one
  2760.     say arg(2,'0')            ==>1
  2761.  
  2762. B2C()
  2763.  
  2764. Usage:B2C(string)
  2765. Converts a string of binary digits(0,1)into the corresponding(packed)character
  2766. representation. The conversion is the same as though the argument string had
  2767. been specified as a literal binary string(e.g. '1010'B). Blanks are permitted
  2768. in the string,but only at byte boundaries. This function is particularly useful
  2769. for creating strings that are to be used as bit masks.
  2770. See also:X2C()
  2771. Examples:
  2772.  
  2773.     say b2c('00110011')        ==>3
  2774.     say b2c('01100001')        ==>a
  2775.  
  2776. BITAND()
  2777.  
  2778. Usage:BITAND(string1,string2,[pad])
  2779. The argument strings are logically ANDed together,with the length of the result
  2780. being the longer of the two operand strings. If a pad character is supplied,the
  2781. shorter string is padded on the right;otherwise,the operation terminates at the
  2782. end of the shorter string and the remainder of the longer string is appended to
  2783. the result.
  2784. Example:
  2785.  
  2786.     bitand('0313'x,'FFF0'x)        ==>'0310'x
  2787.  
  2788.                 52
  2789.  
  2790. BITCHG()
  2791. Usage:BITCHG(string,bit)
  2792. Changes the state of the specified bit in the argument string. Bit numbers are
  2793. defined such that bit 0 is the low-order bit of the rightmost byte of the
  2794. string.
  2795. Example:
  2796.     bitchg('0313'x,4)        ==>'0303'x
  2797.  
  2798. BITCLR()
  2799. Usage:BITCLR(string,bit)
  2800. Clears(sets to zero)the specified bit in the argument string. Bit numbers are
  2801. defined such that bit 0 is the low-order bit of the rightmost byte of the
  2802. string.
  2803. Example:
  2804.     bitclr('0313'x,4)        ==>'0303'x
  2805.  
  2806. BITCOMP()
  2807. Usage:BITCOMP(string1,string2,[pad])
  2808. Compares the argument strings bit-by-bit,starting at bit number 0. The returned
  2809. value is the bit number of the first bit in which the strings differ,or -1 if
  2810. the strings are identical.
  2811. Examples:
  2812.     bitcomp('7F'x,'FF'x)        ==>7
  2813.     bitcomp('FF'x,'FF'x)        ==>-1
  2814.  
  2815. BITOR()
  2816. Usage:BITOR(string1,string2,[pad])
  2817. The argument strings are logically ORed together,with the length of the result
  2818. being the longer of the two operand strings. If a pad character is supplied,the
  2819. shorter string is padded on the right;otherwise,the operation terminates at the
  2820. end of the shorter string and the remainder of the longer string is appended to
  2821. the result.
  2822. Example:
  2823.     bitor('0313'x,'003F'x)        ==>'033F'x
  2824.  
  2825. BITSET()
  2826. Usage:BITSET(string,bit)
  2827. Sets the specified bit in the argument string is 1. Bit numbers are defined
  2828. such that bit 0 is the low-order bit of the rightmost byte of the string.
  2829. Example:
  2830.     bitset('0313'x,2)        ==>'0317'x
  2831.  
  2832. BITTST()
  2833. Usage:BITTST(string,bit)
  2834. The boolean return indicates the state of the specified bit in the argument
  2835. string.
  2836.  
  2837.                 53
  2838.  
  2839. Bit numbers are defined such that bit 0 is the low-order bit of the rightmost
  2840. byte to the string.
  2841. Example:
  2842.     bittst('0313'x,4)        ==>1
  2843.  
  2844. BITXOR()
  2845. Usage:BITAND(string1,string2,[pad])
  2846. The argument strings are logically exclusively-ORed together,with the length of
  2847. the result being the longer of the two operand strings. If a pad character is
  2848. supplied,the shorter string is padded on the right;otherwise,the operation
  2849. terminates at the end of the shorter string and the remainder of the longer
  2850. string is appended to the result.
  2851. Example:
  2852.     bitxor('0313'x,'001F'x)        ==>'030C'x
  2853.  
  2854. C2B()
  2855. Usage:C2B(string)
  2856. Converts the character string into the equivalent string of binary digits.
  2857. See Also:C2X()
  2858. Example:
  2859.     say c2b('abc')            ==>011000010110001001100011
  2860.  
  2861. C2D()
  2862. Usage:C2D(string,[n])
  2863. Converts the string argument from its character representation to the
  2864. corresponding decimal number,expressed as ASCII digits(0-9). If n is supplied,
  2865. the character string is considered to be a number expressed in n bytes. The
  2866. string is truncated or padded with nulls on the left as required,and the sign
  2867. bit is extended for the conversion.
  2868. Examples:
  2869.     say c2d('0020'x)        ==>32
  2870.     say c2d('FFFF')            ==>1
  2871.     say c2d('FF0100',x,2)        ==>256
  2872.  
  2873. C2X()
  2874. Usage:C2X(string)
  2875. Converts the string argument from its character representation to the
  2876. corresponding hexadecimal number,expressed as the ACSII characters 0-9 and A-F.
  2877. See Also:C2B()
  2878. Example:
  2879.     say c2x('abc')            ==>616263
  2880.  
  2881.                 54
  2882.  
  2883. CENTER() or CENTRE()
  2884. Usage:CENTER(string,length,[pad])or CENTRE(string,length,[pad])
  2885. Centers the string argument in a string with the specified length. If the
  2886. length is longer than that of the string,pad characters or blanks are added as
  2887. necessary.
  2888. Examples:
  2889.     say center('abc',6)        ==>' abc '
  2890.     say center('abc',6,'+')        ==>'+abc++'
  2891.     say center('123456',3)        ==>'234'
  2892.  
  2893. CLOSE()
  2894. Usage:CLOSE(file)
  2895. Closes the file specified by the given logical name. The returned value is a
  2896. boolean success flag,and will be 1 unless the specified file was not open.
  2897. Example:
  2898.     say close('input')        ==>1
  2899.  
  2900. COMPRESS()
  2901. Usage:COMPRESS(string,[list])
  2902. If the list argument is omitted,the function removes leading,trailing,or
  2903. embedded blank characters from the string argument. If the optional list is
  2904. supplied,it specifies the characters to be removed from the string.
  2905. Examples:
  2906.     say compress (' why not ')    ==>whynot
  2907.     say compress ('++12-34-+','+-') ==>1234
  2908.  
  2909. COMPARE()
  2910. Usage:COMPARE(string1,string2,[pad])
  2911. Compares two strings and returns the index of the first position in which they
  2912. differ,or 0 if the strings are identical. The shorter string is padded as
  2913. required using the supplied character or blanks.
  2914. Examples:
  2915.     say compare('abcde','abcce')    ==>4
  2916.     say compare('abcde',abcde')    ==>0
  2917.     say compare('abc++','abc+-','+') ==>5
  2918.  
  2919. COPIES()
  2920. Usage:COPIES(string,number)
  2921. Creates a new string by concatenating the specified number of copies of the
  2922. original. The number argument may be zero,in which case the null string is
  2923. returned.
  2924.  
  2925.                 55
  2926.  
  2927. Example:
  2928.     say copies('abc',3)        ==>abcabcabc
  2929.  
  2930. D2C()
  2931. Usage:D2C(number)
  2932. Creates a string whose value is the binary(packed)representation of the given
  2933. decimal number.
  2934. Example:
  2935.     d2c(31)                ==>'1F'x
  2936.  
  2937. DATATYPE()
  2938. Usage:DATATYPE9string,[option])
  2939. If the option parameter is not specified,DATATYPE()tests whether the string
  2940. parameter is a valid number and returns either NUM or CHAR. If an option
  2941. keyword is given,the boolean return indicates whether the string satisfied the
  2942. requested test. The following option keywords are recognized:
  2943.  
  2944.             Table 6.1 DATATYPE()Options
  2945.  
  2946.     KEYWORD            CHARACTERS ACCEPTED
  2947.     Alphanumeric        Alphabetics (A-Z,a-z)
  2948.                 or Numerics (0-9)
  2949.     Binary            Binary Digits String
  2950.     Lowercase        Lowercase Alphabetics (a-z)
  2951.     Mixed            Mixed Upper/Lowercase
  2952.     Numeric            Valid Numbers
  2953.     Symbol            Valid REXX Symbols
  2954.     Upper            Uppercase Alphabetics (A-Z)
  2955.     Whole            Integer Numbers
  2956.     X            Hex Digits String
  2957. Examples:
  2958.     say datatype('123')            ==>NUM
  2959.     say datatype('1a f2','x')        ==>1
  2960.     say datatype('aBcde','L')        ==>0
  2961.  
  2962. DELSTR()
  2963. Usage:DELSTR(string,n,[length])
  2964. Deletes the substring of the string argument beginning with the nth character
  2965. for the specified length in characters. The default length is the remaining
  2966. length of the string.
  2967. Example:
  2968.     say delstr('123456',2,3)        ==>156
  2969.  
  2970.                 56
  2971.  
  2972. DELWORD()
  2973. Usage:DELWORD(string,n,[length])
  2974. Deletes the substring of the string argument beginning with the nth word for
  2975. the specified length in words. The default length is the remaining length of
  2976. the string. The deleted string includes any trailing blanks following the last
  2977. word.
  2978. Examples:
  2979.     say delword('Tell me a story',2,2)==>'Tell story'
  2980.     say delword('one two three',3)      ==>'one two '
  2981.  
  2982. EOF()
  2983. Usage:EOF(file)
  2984. Checks the specified logical file name and returns the boolean value 1(True)if
  2985. the end-of-file has been reached,and 0(False)otherwise.
  2986. Example:
  2987.     say eof(infile)            ==>1
  2988.  
  2989. ERRORTEXT()
  2990. Usage:ERRORTEXT(n)
  2991. Returns the error message associated with the specified ARexx code. The null
  2992. string is returned if the number is not a valid error code.
  2993. Example:
  2994.     say errortext(41)        ==>Invalid expression
  2995.  
  2996. EXISTS()
  2997. Usage:EXISTS(filename)
  2998. Tests whether an external file of the given filename exists. The name string
  2999. may include device and directory specifications.
  3000. Example:
  3001.     say exists('df0:c/ed')        ==>1
  3002.  
  3003. EXPORT()
  3004. Usage:EXPORT(address,[string],[length],[pad])
  3005. Copies data from the (optional) string into a previously-allocated memory area,
  3006. which must be specified as a 4-byte address. The length parameter specifies the
  3007. maximum number of characters to be copied; the default is the length of the
  3008. string. If the specified length is longer than the string,the remaining area is
  3009. filled with the pad character or nulls('00'x). The returned value is the number
  3010. of characters copied.
  3011.  
  3012. Caution is advised in using this function. Any area of memory can be
  3013. overwritten,possibly causing a system crash. Task switching is forbidden while
  3014. the copy is being done,so system performance may be degraded if long strings
  3015. are copied.
  3016. See Also:IMPORT(),STORAGE()
  3017.  
  3018.                 57
  3019.  
  3020. Example:
  3021.     count = export('0004 0000'x,'The answer')
  3022.  
  3023. FREESPACE()
  3024. Usage:FREESPACE(address,length)
  3025. Returns a block of memory of the given length to the interpreter's internal
  3026. pool. The address argument must be a 4-byte string obtained by a prior call to
  3027. GETSPACE(),the internal allocator. It is not always necessary to release
  3028. internally-allocated memory,since it will be released to the system when the
  3029. program terminates. However,if a very large block has been allocated,returning
  3030. it to the pool may avoid memory space problems. The return value is a boolean
  3031. success flag.
  3032. See Also:GETSPACE()
  3033. Example:
  3034.     say freespace('00042000'x,32)        ==>1
  3035.  
  3036. GETCLIP()
  3037. Usage:GETCLIP(name)
  3038. Searches the Clip List for an entry matching the supplied name parameter,and
  3039. returns the associated value string. The name-matching is case-sensitive,and
  3040. the null string is returned if the name cannot be found. The usage and
  3041. maintenance of Clip List entries is described in the Chapter 9.
  3042. See Also:SETCLIP()
  3043. Example:
  3044.     /* Assume 'numbers' contains 'PI=3.14159'    */
  3045.     say getclip('numbers')        ==>PI=3.14159
  3046.  
  3047. GETSPACE()
  3048. Usage:GETSPACE(length)
  3049. Allocates a block of memory of the specified length from the interpreter's
  3050. internal pool. The returned value is the 4-byte address of the allocated block,
  3051. which is not cleared or otherwise initialized. Internal memory is automatically
  3052. returned to the system when the ARexx program terminates,so this function
  3053. should not be used to allocate memory for use by external programs. The Support
  3054. Library(described in Appendix D)includes the function ALLOCMEM()which to
  3055. allocate memory from the system free list.
  3056. See Also:FREESPACE()
  3057. Example:
  3058.     say c2x(getspace(32))        ==>'0003BF40'x
  3059.  
  3060. HASH()
  3061. Usage:HASH(string)
  3062. Returns the hash attribute of a string as a decimal number,and updates the
  3063. internal hash value of the string.
  3064.  
  3065.                 58
  3066.  
  3067. Example:
  3068.     say hash('1')            ==>49
  3069.  
  3070. IMPORT()
  3071. Usage:IMPORT(address,[length])
  3072. Creates a string by copying data from the specified 4-byte address. If the
  3073. length parameter is not supplied,the copy terminates when a null byte is found.
  3074. See Also:EXPORT()
  3075. Example:
  3076.     extval = import('0004 0000'x,8)
  3077.  
  3078. INDEX()
  3079. Usage:INDEX(string,pattern,[start])
  3080. Searches for the first occurrence of the pattern argument in the string
  3081. argument,beginning at the specified start position. The default start position
  3082. is 1. The returned value is the index of the matched pattern,or 0 if the
  3083. pattern was not found.
  3084. Examples:
  3085.     say index("123456","23")    ==>2
  3086.     say index("123456","77")    ==>0
  3087.     say index("123123","23",3)    ==>5
  3088.  
  3089. INSERT()
  3090. Usage:INSERT(new,old,[start],[length],[pad])
  3091. Inserts the new string into the old string after the specified start position.
  3092. The default starting position is 0. The new string is truncated or padded to
  3093. the specified length as required,using the supplied pad character or blanks. If
  3094. the start position is beyond the end of the old string,the old string is padded
  3095. on the right.
  3096. Examples:
  3097.     say insert('ab,'12345')        ==>ab12345
  3098.     say insert('123','++',3,5,'-')    ==>++-123--
  3099.  
  3100. LASTPOS()
  3101. Usage:LASTPOS(pattern,string,[start])
  3102. Searches backwards for the first occurrence of the pattern argument in the
  3103. string argument,beginning at the specified start position. The default starting
  3104. position is the end of the string. The returned value is the index of the
  3105. matched pattern,or 0 if the pattern was not found.
  3106.  
  3107.                 59
  3108.  
  3109. Examples:
  3110.     say lastpos("123234","2")    ==>4
  3111.     say lastpos("123234","5")    ==>0
  3112.     say lastpos("123234","2",3)    ==>2
  3113.  
  3114. LEFT()
  3115. Usage:LEFT(string,length,[pad])
  3116. Returns the leftmost substring in the given string argument with the specified
  3117. length. If the substring is shorter than the requested length,it is padded on
  3118. the left with the supplied pad character or blanks.
  3119. Examples:
  3120.     say left('123456',3)        ==>123
  3121.     say left('123456',8,'+')    ==>123456++
  3122.  
  3123. LENGTH()
  3124. Usage:LENGTH(string)
  3125. Returns the length of the string.
  3126. Example:
  3127.     say length('three')        ==>5
  3128.  
  3129. MAX()
  3130. Usage:MAX(number,number[,number,...])
  3131. Returns the maximum of the supplied arguments,all of which must be numeric. At
  3132. least two parameters must be supplied.
  3133. Example:
  3134.     say max(2.1,3,-1_        ==>3
  3135.  
  3136. MIN()
  3137. Usage:MIN(number,number[,number,...])
  3138. Returns the minimum of the supplied arguments,all of which must be numeric. At
  3139. least two parameters must be supplied.
  3140. Example:
  3141.     say min(2.1,3,-1)        ==>-1
  3142.  
  3143. OPEN()
  3144. Usage:OPEN(file,filename,['Append' | 'Read' | 'Write'])
  3145. Opens an external file for the specified operation. The file argument defines
  3146. the logical name by which the file will be referenced. The filename is the
  3147. external name of the file,and may include device and directory specifications.
  3148. The function returns a boolean value that indicates whether the operation was
  3149. successful. There is no limit to the number of files that can be open
  3150.  
  3151.                 60
  3152.  
  3153. simultaneusly,and all open files are closed automatically when the program
  3154. exits.
  3155. See Also:CLOSE(),READ(),WRITE()
  3156. Examples:
  3157.     say open('MyCon','CON:160/50/320/100/MyCon/cds') ==>1
  3158.     say open('outfile','ram:temp','W')         ==>1
  3159.  
  3160. OVERLAY()
  3161. Usage:OVERLAY(new,old,[start],[length],[pad])
  3162. Overlays the new string onto the old string beginning at the specified start
  3163. position,which must be positive. The default starting position is 1. The new
  3164. string is truncated or padded to the specified length as required,using the
  3165. supplied pad character or blanks. If the start position is beyond the end of
  3166. the old string,the old string is padded on the right.
  3167. Examples:
  3168.     say overlay('bb,'abcd')            ==>bbcd
  3169.     say overlay('4','123',5,5,'-')        ==>123--4----
  3170.  
  3171. POS()
  3172. Usage:POS(pattern,string,[start])
  3173. Searches for the first occurrence of the pattern argument in the string
  3174. argument,beginning at the position specified by the start argument. The default
  3175. starting position is 1. The returned value is the index of the matched
  3176. string,or 0 if the pattern wasn't found.
  3177. Examples:
  3178.     say pos('23','123234')            ==>2
  3179.     say pos('77','123234')            ==>0
  3180.     say pos('23','123234',3)        ==>4
  3181.  
  3182. PRAGMA()
  3183. Usage:PRAGMA(option,[value])
  3184. This function allows a program to change various attributes relating to the
  3185. system environment within which the program executes. The option argument is a
  3186. keyword that specifies an environmental attribute;the currently implemented
  3187. options are Directory and Priority. The value argument supplies the new
  3188. attribute value to be installed. The value returned by the function depends on
  3189. the attribute selected. Some attributes return the previous value
  3190. installed,while others may simply set a boolean success flag. The currently
  3191. defined option keywords are listed below.
  3192.  
  3193. DIRECTORY. Specifies a new "current" directory. The current directory is used
  3194. as the "root" for filenames that do not explicitly include a device
  3195. specification. The return value is a boolean success flag.
  3196.  
  3197. PRIORITY. Specifies a new task priority. The priority value must be an integer
  3198. in the range -128 to 127,but the practical range is much more limited. ARexx
  3199. programs should never be run at a priority higher than that of the resident
  3200. process,which currently runs at priority 4. The returned value is the previous
  3201. priority level.
  3202.  
  3203.                 61
  3204.  
  3205. Examples:
  3206.     say pragma('priority',-5)        ==>0
  3207.     call pragma 'Directory','df0:system'
  3208.  
  3209. RANDOM()
  3210. Usage:RANDOM([min],[max],[seed])
  3211. Returns a pseudorandom integer in the interval specified by the min and max
  3212. arguments. The default minimum value is 0 and the default maximum value is 999.
  3213. The interval max-min must be less than or equal to 1000. If a greater range of
  3214. random integers is required,the values from the RANDU()function can be suitable
  3215. scaled and translated.
  3216.  
  3217. The seed argument can be supplied to initialize the internal state of the
  3218. random number generator.
  3219. See Also:RANDU()
  3220. Example:
  3221.     thisroll = random(1,6)    /* might be 1    */
  3222.     nextroll = random(1,6)    /* snake eyes?    */
  3223.  
  3224. RANDU()
  3225. Usage:RANDU([seed])
  3226. Returns a uniformly-distributed pseudorandom number between 0 and 1. The number
  3227. of digits of precision in the result is always equal to the current Numeric
  3228. Digits setting. With the choice of suitable scaling and translation values,
  3229. RANDU()can be used to generate pseudorandom numbers on an arbitrary interval.
  3230.  
  3231. The optional seed argument is used to initialize the internal state of the
  3232. random number generator.
  3233. See Also:RANDOM()
  3234. Example:
  3235.     firsttry = randu()    /* 0.371902021? */
  3236.     numeric digits 3
  3237.     tryagain = randu()    /* 0.873?    */
  3238.  
  3239. READCH()
  3240. Usage:READCH(file,length)
  3241. Reads the specified number of characters from the given logical file into a
  3242. string. The length of the returned string is the actual number of characters
  3243. read,and may be less than the requested length if,for example,the end-of-file
  3244. was reached.
  3245. See Also:READLN()
  3246. Example:
  3247.     instring = readch('input',10)
  3248.  
  3249.                 62
  3250.  
  3251. READLN()
  3252. Usage:READLN(file)
  3253. Reads characters from the given logical file into a string until a "newline"
  3254. character is found. The returned string does not include the "newline".
  3255. See Also:READCH()
  3256. Examples:
  3257.     instring = readln('MyFile')
  3258.  
  3259. REMLIB()
  3260. Usage:REMLIB(name)
  3261. Removes an entry with the given name from the Library List maintained by the
  3262. resident process. The boolean return is 1 if the entry was found and
  3263. successfully removed. Note that this function does not make a distinction
  3264. between function libraries and function hosts,but simply removes a named entry.
  3265. See Also:ADDLIB()
  3266. Example:
  3267.     say remlib('MyLibrary.library')==>1
  3268.  
  3269. REVERSE()
  3270. Usage:REVERSE(string)
  3271. Reverses the sequence of characters in the string.
  3272. Example:
  3273.     say reverse('?ton yhw')        ==>why not?
  3274.  
  3275. RIGHT()
  3276. Usage:RIGHT(string,length,[pad])
  3277. Returns the rightmost substring in the given string argument with the specified
  3278. length. If the substring is shorter than the requested length,it is padded on
  3279. the left with the supplied pad character or blanks.
  3280. Examples:
  3281.     say right('123456',4)        ==>3456
  3282.     say right('123456',8,'+')    ==>++123456
  3283.  
  3284. SEEK()
  3285. Usage:SEEK(file,offset,['Begin' | 'Current' | 'End'])
  3286. Moves to a new position in the given logical file,specified as an offset from
  3287. an anchor position. The default anchor is Current. The returned value is the
  3288. new position relative to the start of the file.
  3289. Examples:
  3290.     say seek('input',10,'B')    ==>10
  3291.     say seek('input',O,'E')        ==>356  /* file length    */
  3292.  
  3293.                 63
  3294.  
  3295. SETCLIP()
  3296. Usage:SETCLIP(name,[value])
  3297. Adds a name-value pair to the Clip List maintained by the resident process. If
  3298. an entry of the same name already exists,its value is updated to the supplied
  3299. value string. Entries may be removed by specifying a null value. The function
  3300. returns a boolean value that indicates whether the operation was successful.
  3301. Examples:
  3302.     say setclip('path','df0:s')    ==>1
  3303.     say setclip('path')        ==>1
  3304.  
  3305. SHOW()
  3306. Usage:SHOW(option,[name],[pad])
  3307. Returns the names in the resource list specified by the option argument,or
  3308. tests to see whether an entry with the specified name is available. The
  3309. currently implemented options keywords are Clip,Files,Libraries,and Ports,
  3310. which are described below.
  3311.  
  3312. Clip. Examines the names in the Clip List.
  3313. Files. Examines the names of the currently open logical file names.
  3314. Libraries. Examines the names in the Library List,which are either function
  3315. libraries or function hosts.
  3316. Ports. Examine the names in the system Ports List.
  3317.  
  3318. If the name argument is omitted,the function returns a string with the resource
  3319. names separated by a blank space or the pad character,if one was supplied. If
  3320. the name argument is given,the returned boolean value indicates whether the
  3321. name was found in the resource list. The name entries are case-sensitive.
  3322.  
  3323. SIGN()
  3324. Usage:SIGN(number)
  3325. Returns 1 if the number argument is positive or zero,and -1 if number is
  3326. negative. The argument must be numeric.
  3327. Examples:
  3328.     say sign(12)            ==>1
  3329.     say sign(-33)            ==>-1
  3330.  
  3331. SPACE()
  3332. Usage:SPACE(string,n,[pad])
  3333. Reformats the string argument so that there are n spaces(blank characters)
  3334. between each pair of words. If the pad character is specified,it is used
  3335. instead of blanks as the separator character. Specifying n as 0 will remove all
  3336. blanks from the string.
  3337. Examples:
  3338.     say space('Now is the time',3)    ==>'Now   is   the   time'
  3339.     say space('Now is the time',0)    ==>'Nowisthetime'
  3340.     say space('1 2 3',1,'+')    ==>'1+2+3'
  3341.  
  3342.                 64
  3343.  
  3344. STORAGE()
  3345. Usage:STORAGE([address],[string],[length],[pad])
  3346. Calling STORAGE()with no arguments returns the available system memory. If the
  3347. address argument is given,it must be a 4-byte string,and the function copies
  3348. data from the(optional)string into the indicated memory area. The length
  3349. parameter specifies the maximum number of bytes to be copied,and defaults to
  3350. the length of the string. If the specified length is longer than the string,the
  3351. remaining area is filled with the pad character or nulls('00'x.)
  3352.  
  3353. The returned value is the previous contents of the memory area. This can be
  3354. used in a subsequent call to restore the original contents.
  3355.  
  3356. Caution is advised in using this function. Any area of memory can be
  3357. overwritten,possibly causing a system crash. Task switching is forbidden while
  3358. the copy is being done,so system performance may be degraded if long strings
  3359. are copied.
  3360. See Also:EXPORT()
  3361. Examples:
  3362.     say storage()            ==>248400
  3363.     oldval = storage('0004 000'x,'The answer')
  3364.     call storage '0004 0000'x,,32,'+'
  3365.  
  3366. STRIP()
  3367. Usage:STRIP(string,[{'B' | 'L' | 'T'}],[pad])
  3368. If neither of the optional parameters is supplied,the function removes both
  3369. leading and trailing blanks from the string argument. The second argument
  3370. specifies whether Leading,Trailing,or Both(leading and trailing)characters are
  3371. to be removed. The optional pad(or unpad,perhaps)argument selects the character
  3372. to be removed.
  3373. Examples:
  3374.     say strip(' say what? ')        ==>'say what?'
  3375.     say strip(' say what? ','L')        ==>'say what? '
  3376.     say strip('++123+++','B','+')        ==>'123'
  3377.  
  3378. SUBSTR()
  3379. Usage:SUBSTR(string,start,[length],[pad])
  3380. Returns the substring of the string argument beginning at the specified start
  3381. position for the specified length. The starting position must be positive,and
  3382. the default length is the remaining length of the string. If the substring is
  3383. shorter than the requested length,it is padded on the left with the blanks or
  3384. the specified pad character.
  3385. Examples:
  3386.     say substr('23456',4,2)        ==>45
  3387.     say substr('myname',3,6,'=')    ==>name==
  3388.  
  3389.                 65
  3390.  
  3391. SUBWORD()
  3392. Usage:SUBWORD(string,n,[length])
  3393. Returns the substring of the string argument beginning with the nth word for
  3394. the specified length in words. The default length is the remaining length of
  3395. the string. The returned string will never have leading or trailing blanks.
  3396. Example:
  3397.     say subword('Now is the time ',2,2)    ==>is the
  3398.  
  3399. SYMBOL()
  3400. Usage:SYMBOL(name)
  3401. Tests whether the name argument is a valid REXX symbol. If the name is not a
  3402. valid symbol,the function returns the string BAD. Otherwise,the returned string
  3403. is LIT if the symbol is uninitialized and VAR if it has been assigned a value.
  3404. Examples:
  3405.     say symbol('J')            ==>VAR
  3406.     say symbol('x')            ==>LIT
  3407.     say symbol('++')        -->BAD
  3408.  
  3409. TIME()
  3410. Usage:TIME(option)
  3411. Returns the current system time or controls the internal elapsed time counter.
  3412. The valid option keywords are listed below.
  3413.  
  3414.             Table 6.2 TIME()Options
  3415.     
  3416.     OPTION KEYWORD        DESCRIPTION
  3417.     Elapsed            Elapsed time in seconds.
  3418.     Hours            Current time in hours since midnight
  3419.     Minutes            Current time in minutes since midnight
  3420.     Reset            Reset the elapsed time clock
  3421.     Seconds            Current time in seconds since midnight
  3422.  
  3423. If no option is specified,the function returns the current system time in the
  3424. form HH:MM:SS.
  3425. Examples:
  3426.     /* Suppose that the time is 1:02 AM ...        */
  3427.     say time('Hours')        ==>1
  3428.     say time('m')            ==>62
  3429.     say time('S')            ==>3720
  3430.     call time 'R'            /* reset timer    */
  3431.     say time('E')            ==>.020
  3432.  
  3433.                 66
  3434.  
  3435. TRACE()
  3436. Usage:TRACE(option)
  3437. Sets the tracing mode to that specified by the option keyword,which must be one
  3438. of the valid alphabetic or prefix options. The tracing options are described in
  3439. Chapter 7. The TRACE()function will alter the tracing mode even during
  3440. interactive tracing,when TRACE instructions in the source program are ignored.
  3441. The returned value is the mode in effect before the function call;this allows
  3442. the previous trace mode to be restored later.
  3443. Example:
  3444.     /* Assume tracing mode is ?AL        */
  3445.     say trace('Results')        ==>?A
  3446.  
  3447. TRANSLATE()
  3448. Usage:TRANSLATE(string,[output],[input],[pad])
  3449. This function constructs a translation table and uses it to replace selected
  3450. characters in the argument string. If only the string argument is given,it is
  3451. translated to uppercase. If an input table is supplied,it modifies the
  3452. translation table so that characters in the argument string that occur in the
  3453. input table are replaced with the corresponding character in the output table.
  3454. Characters beyond the end of the output table are replaced with the specified
  3455. pad character or a blank.
  3456.  
  3457. Note that the result string is always of the same length as the original
  3458. string. The input and output tables may be of any length.
  3459. Examples:
  3460.     say translate("abcde","123","cbade","+")    ==>321++
  3461.     say translate("low")                ==>LOW
  3462.     say translate("0110","10","01")            ==>1001
  3463.  
  3464. TRIM()
  3465. Usage:TRIM(string)
  3466. Removes trailing blanks from the string argument.
  3467. Example:
  3468.     say length(trim(' abc  '))    ==>4
  3469.     
  3470. UPPER()
  3471. Usage:UPPER(string)
  3472. Translates the strip to uppercase. The action of this function is equivalent to
  3473. that of TRANSLATE(string),but it is slightly faster for short strings.
  3474. Example:
  3475.     say upper('One Fine Day')    ==>ONE FINE DAY
  3476.  
  3477.                 67
  3478.  
  3479. VALUE()
  3480. Usage:VALUE(name)
  3481. Returns the value of the symbol represented by the name argument.
  3482. Example:
  3483.     /* Assume that J has the value of 12        */
  3484.     say value('j')            ==>12
  3485.  
  3486. VERIFY()
  3487. Usage:VERIFY(string,list,['Match'])
  3488. If the Match argument is omitted,the function returns the index of the first
  3489. character in the string argument which is not contained in the list argument,or
  3490. 0 if all of the characters are in the list. If the Match keyword is supplied,
  3491. the function returns the index of the first character which is in the list,or 0
  3492. if none of the characters are.
  3493. Examples:
  3494.     say verify('123456','0123456789')    ==>0
  3495.     say verify('123a56','0123456789')    ==>4
  3496.     say verify('123a45','abcdefghij','m')    ==>4
  3497.  
  3498. WORD()
  3499. Usage:WORD(string,n)
  3500. Returns the nth word in the string argument,or the null string if there are
  3501. fewer than n words.
  3502. Example:
  3503.     say word('Now is the time ',2)        ==>is
  3504.  
  3505. WORDINDEX()
  3506. Usage:WORINDEX(string,n)
  3507. Returns the starting position of the nth word in the argument string,or 0 if
  3508. there are fewer than n words.
  3509. Example:
  3510.     say wordindex('Now is the time ',3)    ==>8
  3511.  
  3512. WORDLENGTH()
  3513. Usage:WORDLENGTH(string,n)
  3514. Returns the length of the nth word in the string argument.
  3515. Example:
  3516.     say wordlength('one two three',3)    ==>5
  3517.  
  3518.                 68
  3519.  
  3520. WORDS()
  3521. Usage:WORDS(string)
  3522. Returns the number of words in the string argument.
  3523. Example:
  3524.     say words("You don't say!")        ==>3
  3525.  
  3526. WRITECH()
  3527. Usage:WRITECH(file,string)
  3528. Writes the string argument to the given logical file. The returned value is the
  3529. actual number of characters written.
  3530. Example:
  3531.     say writech('output','Testing')        ==>7
  3532.  
  3533. WRITELN()
  3534. Usage:WRITELN(file,string)
  3535. Writes the string argument to the given logical file with a "newline" appended.
  3536. The returned value is the actual number of characters written.
  3537. Example:
  3538.     say writeln('output','Testing')        ==>8
  3539.  
  3540. X2C()
  3541. Usage:X2C(string)
  3542. Converts a string of hex digits into the(packed)character representation. Blank
  3543. characters are permitted in the argument string at byte boundaries.
  3544. Examples:
  3545.     say x2c('12ab')                ==>'12ab'x
  3546.     say x2c('12 ab')            ==>'12ab'x
  3547.  
  3548. XRANGE()
  3549. Usage:XRANGE([start],[end])
  3550. Generates a string consisting of all characters numerically between the
  3551. specified start and end values. The default start character is '00'x,and the
  3552. default end character is 'FF'x. Only the first character of the start and end
  3553. arguments is significant.
  3554. Examples:
  3555.     say xrange()            ==>'00010203 ... FDFEFF'x
  3556.     say xrange('a','f')        ==>'abcdef'
  3557.     say xrange(,'10'x)        ==>'00010203040506070809010'x
  3558.  
  3559.                 69
  3560.  
  3561.             CHAPTER 7 TRACING AND INTERRUPTS
  3562.  
  3563. ARexx provides tracing and source-level debugging facilities that are unusual
  3564. in a high-level language. Tracing refers to the ability to display selected
  3565. statements in a program as the program executes. When a clause is traced,its
  3566. line number,source text,and related information are displayed on the console.
  3567. The tracing action of the interpreter is determined by a trace option that
  3568. selects which source clauses will be traced,and two modifier flags that control
  3569. command inhibition and interactive tracing.
  3570.  
  3571. The internal interrupt system enables an ARexx program to detect certain
  3572. synchronous or asynchronous events and to take special actions when they occur.
  3573. Events such as a syntax error or an external halt request that would normally
  3574. cause the program to exit can instead be trapped so that corrective actions can
  3575. be taken.
  3576.  
  3577. 7-1 TRACING OPTIONS
  3578.  
  3579. Trace options are sometimes called an alphabetic options,since the keywords
  3580. that select an option can be shortened to one letter for convenience. The
  3581. alphabetic options are:
  3582.  
  3583. ALL. All clauses are traced.
  3584. COMMANDS. All command clauses are traced before being sent to the external
  3585. host. Non-zero return codes are displayed on the console.
  3586. ERRORS. Commands that generate a non-zero return code are traced after the
  3587. clause is executed.
  3588. INTERMEDIATES. All clauses are traced,and intermediate results are displayed
  3589. during expression evaluation. These include the values retrieved for variables,
  3590. expanded compound names,and the results of function calls.
  3591. LABELS. All label clauses are traced as they are executed. A label will be
  3592. displayed each time a transfer of control takes place.
  3593. NORMAL. Command clauses will return codes that exceed the current error failure
  3594. level are traced after execution,and an error message is displayed. This is the
  3595. default trace option.
  3596. RESULTS. All clauses are traced before execution,and the final result of each
  3597. expression is displayed. Values assigned to variables by ARG,PARSE,or PULL
  3598. instructions are also displayed.
  3599. SCAN. This is a special option that traces all clauses and checks for errors,
  3600. but suppresses the actual execution of the statements. It is helpful as a
  3601. preliminary screening steop for a newly-created program.
  3602.  
  3603. The tracing mode can be set using either the TRACE instruction or the TRACE()
  3604. Built-In function. The RESULTS trace option is recommended for general-purpose
  3605. testing. Tracing can be selectively disabled from within a program so that
  3606. previously-tested parts of a program can be skipped.
  3607.  
  3608.                 71
  3609.  
  3610. 7-2 DISPLAY FORMATTING
  3611.  
  3612. Each trace line displayed on the console is indented to show the effective
  3613. control(nesting)level at that clause,and is identified by a special three-
  3614. character code,as shown in Table 7.1 below. The source for each clause is
  3615. preceded by its line number in the program. Expression results or intermediates
  3616. are enclosed in double quotes so that leading and trailing blanks will be
  3617. apparent.
  3618.  
  3619.             TABLE 7.1 TRACING PREFIX CODES
  3620.         
  3621.         CODE        DISPLAYED VALUES
  3622.         +++        Command or syntax error
  3623.         >C>        Expanded compound name
  3624.         >F>        Result of a function call
  3625.         >L>        Label clause
  3626.         >O>        Result of a dyadic operation
  3627.         >P>        Result of a prefix operation
  3628.         >U>        Uninitialized variable
  3629.         >V>        Value of a variable
  3630.         >>>        Expression or template result
  3631.         >.>        "Placeholder" token value
  3632.  
  3633. TRACING OUTPUT
  3634.  
  3635. The tracing output from a program is always directed to one of two logical
  3636. streams. The interpreter first checks for a stream named STDERR,and directs the
  3637. output there if the steam exists. Otherwise the trace output goes to the
  3638. standard output stream STDOUT and will be interleaved with the normal console
  3639. output of the program. The STDERR and STDOUT streams can be opened and closed
  3640. under program control,so the programmer has complete control over the
  3641. destination of tracing output.
  3642.  
  3643. In some cases a program may not have a predefined output stream. For example,a
  3644. program invoked from a host application that did not provide input and output
  3645. streams would not have an output console. To provide a tracing facility for
  3646. such programs,the resident process can open a special global tracing console
  3647. for use by any active program. When this console opens,the interpreter
  3648. automatically opens a stream named STDERR for each ARexx program in which
  3649. STDERR is not currently defined,and the program then diverts its tracing output
  3650. to the new stream.
  3651.  
  3652. The global console can be opened and closed using the command utilities too and
  3653. tcc,respectively. The console may not close immediately upon request,however.
  3654. The resident process waits until all active programs have diverted their
  3655. tracing streams back to the default state before actually closing the console.
  3656. Applications programs may provide direct control over the tracing console by
  3657. sending request packets to the resident process,which is discussed in Chapter
  3658. 10.
  3659.  
  3660. The trace stream(STDERR or STDOUT)is also used for trace input,so a program in
  3661. interactive tracing mode will wait for user input from this console. The global
  3662. tracing console is always shared among all currently active programs. Since it
  3663. may be confusing to have several programs simultaneously writing to the same
  3664. console,it is recommended that only one program at a time be traced using the
  3665. global console.
  3666.  
  3667.                 72
  3668.  
  3669. COMMAND INHIBITION
  3670.  
  3671. ARexx provides a tracing mode called command inhibition that suppresses host
  3672. commands. In this mode command clauses are evaluated in the normal manner,but
  3673. the command is not actually sent to the external host,and the return code is
  3674. set to zero. This provides a way to test programs that issue potentially
  3675. destructive commands,such as erasing files or formatting disks. Command
  3676. inhibition does not apply to command clauses that are entered interactively.
  3677. These commands are always performed,but the value of the special variable RC is
  3678. left unchanged.
  3679.  
  3680. Command inhibition may be used in conjunction with any trace option. It is
  3681. controlled by the "!" character,which may appear by itself or may precede any
  3682. of the alphabetic options in a TRACE instruction. Each occurrence of the "!"
  3683. character "toggles" the inhibition mode currently in effect. Command inhibition
  3684. is cleared when tracing is set to OFF.
  3685.  
  3686. 7-3 INTERACTIVE TRACING
  3687.  
  3688. Interactive tracing is a debugging facility that allows the user to enter
  3689. source statements while a program is executing. These statements may be used to
  3690. examine or modify variable values,issue commands,or otherwise interact with the
  3691. program. Any valid language statements can be entered interactively,with the
  3692. same rules and restrictions that apply to the INTERPRET instruction. In
  3693. particular,compound statements such as DO and SELECT must be complete within
  3694. the entered line.
  3695.  
  3696. Interactive tracing can be used with any of the trace options. While in
  3697. interactive tracing mode,the interpreter pauses after each traced clause and
  3698. prompts for input with the code "+++." At each pause,three types of user
  3699. responses are possible.
  3700.  
  3701.     If a null line is entered,the program continues to the next pause
  3702.     point.
  3703.     If an "=" character is entered,the preceding clause is executed again.
  3704.     Any other input is treated as a debugging statement,and is scanned and
  3705.     executed.
  3706.  
  3707. The pause points during interactive tracing are determined by the tracing
  3708. option currently in effect,as the interpreter pauses only after a traced
  3709. clause. However,certain instructions cannot be safely(or sensibly)re-executed,
  3710. so the interpreter will not pause after executing one of these. The "no-pause"
  3711. instructions are CALL,DO,ELSE,IF,THEN,and OTHERWISE. The interpreter will also
  3712. not pause after any clause that generate and execution error.
  3713.  
  3714. Interactive tracing mode is controlled by the "?" character,either by itself or
  3715. in combination with an alphabetic trace option. Any number of "?" characters
  3716. may precede an option,and each occurrence toggles the mode currently in effect.
  3717. For example,if the current trace option was NORMAL,then "TRACE ?R" would set
  3718. the option to RESULTS and select interactive tracing mode. A subsequent "TRACE
  3719. ?" would turn off interactive tracing.
  3720.  
  3721.                 73
  3722.  
  3723. ERROR PROCESSING
  3724.  
  3725. The ARexx interpreter provides special error processing while it executes
  3726. debugging statements. Errors that occur during interactive debugging are
  3727. reported,but do not cause the program to terminate. This special processing
  3728. applies only to the statements that were entered interactively. Errors occuring
  3729. in the program source statements are treated in the usual way whether or not
  3730. the interpreter is in interactive tracing mode.
  3731.  
  3732. In addition to the special error processing,the interpreter also disables the
  3733. internal interrupt flags during interactive debugging. This is necessary to
  3734. prevent an accidental transfer of control due to an error or uninitialized
  3735. variable. However,if a "SIGNAL label" instruction is entered,the transfer will
  3736. take place,and any remaining interactive input will be abandoned. The SIGNAL
  3737. instruction can still be used to alter the interrupt flags,and the new settings
  3738. will take effect when the interpreter returns to normal processing.
  3739.  
  3740. THE EXTERNAL TRACING FLAG
  3741.  
  3742. The ARexx resident process maintains an external tracing flag that can be used
  3743. to force programs into interactive tracing mode. The tracing flag can be set
  3744. using the ts command utility. When the flag is set,any program not already in
  3745. interactive tracing mode will enter it immediately. The internal trace option
  3746. is set to RESULTS unless it is currently set to INTERMEDIATES or SCAN,in which
  3747. case it remains unchanged. Programs invoked while the external tracing flag is
  3748. set will begin executing in interactive tracing mode.
  3749.  
  3750. The external tracing flag provides a way to regain control over programs that
  3751. are caught in loops or are otherwise unresponsive. Once a program enters
  3752. interactive tracing mode,the user can step through the program statements and
  3753. diagnose the problem. There is one caveat,though:external tracing is global
  3754. flag,so all currently-active programs are affected by it. The tracing flag
  3755. remains set until it is cleared using the "te" command utility. Each program
  3756. maintains an internal copy of the last state of the tracing flag,and sets its
  3757. tracing option to OFF when it observes that the tracing flag has been cleared.
  3758.  
  3759. 7-4 INTERRUPTS
  3760.  
  3761. ARexx maintains an internal interrupt system that can be used to detect and
  3762. trap certain error conditions. When an interrupt is enabled and its
  3763. corresponding condition arises,a transfer of control to the label specific to
  3764. that interrupt occurs. This allows a program to retain control in circumstances
  3765. that might otherwise cause the program to terminate. The interrupt conditions
  3766. can caused by either synchronous events like a syntax error,or asynchronous
  3767. events like a "control-C" break request. Note that these internal interrupts
  3768. are completely separate from the hardware interrupt system managed by the EXEC
  3769. operating system.
  3770.  
  3771. The interrupts supported by ARexx are described below. The name assigned to
  3772. each is actually the label to which control will be tranferred. Thus,a SYNTAX
  3773. interrupt will transfer control to the label "SYNTAX:." Interrupts can be
  3774. enabled or disabled using the SIGNAL instruction. For example,the instruction
  3775. "SIGNAL ON SYNTAX" would enable the SYNTAX interrupt.
  3776.  
  3777.                 74
  3778.  
  3779. BREAK_C. This interrupt will trap a control-C break request generated by DOS.
  3780. If the interrupt is not enabled,the program terminates immediately with the
  3781. error message "Execution halted" and returns with the error code set to 2.
  3782.  
  3783. BREAK_D. The interrupt will detect and trap a control-D break request issued by
  3784. DOS. The break request is ignored if the interrupt is not enabled.
  3785.  
  3786. BREAK_E. The interrupt will detect and trap a control-E break request issued by
  3787. DOS. The break request is ignored if the interrupt is not enabled.
  3788.  
  3789. BREAK_F. The interrupt will detect and trap a control-F break request issued by
  3790. DOS. The break request is ignored if the interrupt is not enabled.
  3791.  
  3792. ERROR. This interrupt is generated by any host command that returns a non-zero
  3793. code.
  3794.  
  3795. HALT. An external halt request will be trapped if this interrupt is enabled.
  3796. Otherwise,the program terminates immediately with the error message "Execution
  3797. halted" and returns with the error code set to 2.
  3798.  
  3799. IOERR. Errors detected by the I/O system will be trapped if this interrupt is
  3800. enabled.
  3801.  
  3802. NOVALUE. An interrupt will occur if an uninitialized variable is used while
  3803. this condition is enabled. The usage could be within an expression,in the UPPER
  3804. instruction,or with the VALUE()built-in function.
  3805.  
  3806. SYNTAX. A syntax or execution error will generate this interrupt. Not all
  3807. errors such errors can be trapped,however. In particular,certain errors
  3808. occurring before a program is actually executing,and those detected by the
  3809. ARexx external interface,cannot be trapped by the SYNTAX interrupt.
  3810.  
  3811. When an interrupt forces a transfer of control,all of the currently active
  3812. control ranges are dismantled,and the interrupt that caused the transfer is
  3813. disabled. This latter action is necessary to prevent a possible recursive
  3814. interrupt loop. Only the control structures in the current environment are
  3815. affected,so an interrupt generated within a function will not affect the
  3816. caller's environment.
  3817.  
  3818. SPECIAL VARIABLES. Two special variables are affected when an interrupt occurs.
  3819. The variable SIGL is always set to the current line number before the transfer
  3820. of control takes place,so that the program can determine which source line was
  3821. being executed. When an ERROR or SYNTAX interrupt occurs,the variable RC is set
  3822. to the error code that caused the condition. For ERROR interrupts this value
  3823. will be a command return code,and can usually be interpreted as an error
  3824. severity level. The value for SYNTAX interrupts is always an ARexx error code.
  3825.  
  3826. Interrupts are useful primarily to allow a program to take special
  3827. error-recovery actions. Such actions might involve informing external programs
  3828. that an error ocurred,or simply reporting further diagnostics to help in
  3829. isolating the problem. In the following example,the program issues a "message"
  3830. command to an external host called "MyEdit" whenever a syntax error is
  3831. detected:
  3832.  
  3833.                 75
  3834.  
  3835.     /* A macro program for 'MyEdit'            */
  3836.     signal on syntax    /* enable interrupt    */
  3837.       .
  3838.       . (normal processing)
  3839.       .
  3840.     exit
  3841.     syntax:            /* syntax error detected*/
  3842.        address 'MyEdit'
  3843.        'message' 'error' rc errortext(rc)
  3844.        exit 10
  3845.  
  3846.                 76
  3847.  
  3848.             CHAPTER 8 PARSING AND TEMPLATES
  3849.  
  3850. Parsing is a operation that extracts substrings from a string and assigns them
  3851. to variables. It corresponds roughly to the notion of a "formatted read" used
  3852. in other languages,but has been generalized in the several ways. Parsing is
  3853. performed using the PARSE instruction or its variants ARG and PULL. The input
  3854. for the operation is called the parse string and can come from several sources;
  3855. these source options are described with the PARSE instruction in Chapter 4.
  3856.  
  3857. Parsing is controlled by a template,a group of tokens that specifies both the
  3858. variables to be given values and the way to determine the value strings.
  3859. Templates were described briefly with the PARSE instruction;the present chapter
  3860. presents a more formal description of their structure and operation.
  3861.  
  3862. 8-1 TEMPLATE STRUCTURE
  3863.  
  3864. The tokens that are valid in a template are symbols,strings,operators,
  3865. parentheses,and commas. Any blanks that may be present as separators are
  3866. removed before the template is processed. The tokens in a template ultimately
  3867. serve to specify one of the two basic template objects:
  3868.  
  3869. Markers determine a scan position within the parse string,and
  3870. Targets are symbols to be assigned a value.
  3871.  
  3872. With these objects in mind,the parsing process can be described as one of
  3873. associating with each target a starting and ending position in the parse
  3874. string. The substring between these positions then becomes the value for the
  3875. target.
  3876.  
  3877. MARKETS. There are three types of marker objects:
  3878.  
  3879. ABSOLUTE markers specify an actual index position in the parse string,
  3880. RELATIVE markers specify a positive or negative offset from the current
  3881. position,and
  3882. PATTERN markers specify a position implicitly,by matching the pattern against
  3883. the parse string beginning at the current scan position.
  3884.  
  3885. TARGETS. Targets,like markers,can affect the scan position if value strings are
  3886. being extracted by tokenization. Parsing by tokenization extracts words(tokens)
  3887. from the parse string, and is used whenever a target is followed immediately
  3888.  
  3889.                 77
  3890.  
  3891. by another target. During tokenization the current scan position is advanced
  3892. past any blanks to the start of the next word. The ending index is the position
  3893. just past the end of the word,so that the value string has neither leading nor
  3894. trailing blanks.
  3895.  
  3896. TEMPLATE OBJECTS
  3897.  
  3898. Each template object is specified by one or more tokens,which have the
  3899. following interpretations.
  3900.  
  3901. SYMBOLS. A symbol token may specify either a target or a marker object. If it
  3902. follows an operator token(+,-,or=),it represents a marker,and the symbol value
  3903. is used as an absolute or relative position. Symbols enclosed in parentheses
  3904. specify pattern markers,and the symbol value is used as the pattern string.
  3905.  
  3906. If neither of the preceding cases applies and the symbol is a variable,then it
  3907. specifies a target. Fixed symbols always specify absolute markers and must be
  3908. whole numbers,except for the period(.)symbol which defines a placeholder
  3909. target.
  3910.  
  3911. STRINGS. A string token always represents a pattern marker.
  3912.  
  3913. PARENTHESES. A symbol enclosed in parentheses is a pattern marker,and the value
  3914. of the symbol is used as the pattern string. While the symbol may be either
  3915. fixed or variable,it will usually be a variable,since a fixed pattern could be
  3916. given more simply as a string.
  3917.  
  3918. OPERATORS. The three operators "+,"-,"and "=" are valid within a template,and
  3919. must be followed by a fixed or variable symbol. The value of the symbol is used
  3920. as a marker and must therefore represent a whole number. The "+" and "-"
  3921. operators signify a relative marker,whose value is negated by the "-" operator.
  3922. The "=" operator indicates an absolute marker,and is optional if the marker is
  3923. defined by a fixed symbol.
  3924.  
  3925. COMMAS. The comma(,)marks the end of a template,and is used as a separator when
  3926. multiple templates are provided with an instruction. The interpreter obtains a
  3927. new parse string before processing each succeeding template. For some source
  3928. options,the new string will be identical to the previous one. The ARG,EXTERNAL,
  3929. and PULL options will generally supply a different string,as will the VAR
  3930. option if the variable has been modified.
  3931.  
  3932. THE SCANNING PROCESS
  3933.  
  3934. Scan positions are expressed as an index in the parse string,and can range from
  3935. 1(the start of the string)to the length of the string plus 1(the end). An
  3936. attempt to set the scan position before the start or after the end of the
  3937. string instead sets it to the beginning or end,respectively.
  3938.  
  3939. The substring specified by two scan indices includes the characters from the
  3940. starting position up to,but not including,the ending position. For example,the
  3941. indices 1 and 10 specify characters 1-9 in the parse string. One additional
  3942. rule is applied if the second scan index is less than or equal to the first: in
  3943. this case the remainder of the parse string is used as the substring. This
  3944. means that a template specificaiton like
  3945.                 78
  3946.  
  3947.     parse arg 1 all 1 first second
  3948.  
  3949. will assign the entire parse string to the variable ALL. Of course,if the
  3950. current scan index is already at the end of the parse string,then the remainder
  3951. is just the null string.
  3952.  
  3953. When a pattern marker is matched against the parse string,the marker position
  3954. is the index of the first character of the matched pattern,or the end of the
  3955. string if no match was found. The pattern is removed from the string whenever a
  3956. match is found. This is the only operation that modifies the parse string
  3957. during the parsing process.
  3958.  
  3959. Templates are scanned from left to right with the initial scan index set to 1,
  3960. the start of the parse string. The scan position is updated each time a marker
  3961. object is encountered,according to the type and value of the marker. Whenever a
  3962. target object is found,the value to be assigned is determined by examining the
  3963. next template object. If the next object is another target,the value string is
  3964. determined by tokenizing the parse string. Otherwise,the current scan position
  3965. is used as the start of the value string,and the position specified by the
  3966. following marker is used as the end point.
  3967.  
  3968. The scan continous until all of the objects in the template have been used.
  3969. Note that every target will be assigned a value;once the parse string has been
  3970. exhausted,the null string is assigned to any remaining targets.
  3971.  
  3972. 8-2 TEMPLATES IN ACTION
  3973.  
  3974. The preceding section is rather abstract,so let's look now at some examples of
  3975. parsing with templates.
  3976.  
  3977. PARSING BY TOKENIZATION
  3978.  
  3979. Computer programs frequently require splitting a string into its component
  3980. words or tokens. This is easily accomplished with a template consisting
  3981. entirely of variables(targets).
  3982.  
  3983.     /* Assume "hammer 1 each $600.00" was entered    */
  3984.     pull item qty untils cost .
  3985.  
  3986. In this example the input line from the PULL instruction is split into words
  3987. and assigned to the variables in the template. The variable item receives the
  3988. value "hammer," qty is set to "1," units is set to "each," and cost gets the
  3989. value "$600.00." The final placeholder(.) is given a null value,since there are
  3990. only four words in the input. However,it forces the preceding variable cost to
  3991. be given a tokenized value. If the placeholder were omitted,the remainder of
  3992. the parse string would be assigned to cost,which would then have a leading
  3993. blank.
  3994.  
  3995. In the next example,the first word of a string is removed and the remainder is
  3996. placed back in the string. The process continues until no more words are
  3997. extracted.
  3998.  
  3999.                 79
  4000.  
  4001.     /* Assume "result" contains a string of words    */
  4002.     do forever
  4003.        /* Get first word of string            */
  4004.        parse var result first result
  4005.        if first == '' then leave
  4006.        /* ... process words ...            */
  4007.        end
  4008.  
  4009. PATTERN PARSING
  4010.  
  4011. The next example uses pattern markers to extract the desired fields. The
  4012. "pattern" in this case is very simple -- just a single character -- but in
  4013. general can be an arbitrary string of any length. This form of parsing is
  4014. useful whenever delimiter characters are present in the parse string.
  4015.  
  4016.     /* Assume an argument string "12,34.5,1        */
  4017.     arg hours ',' rate ',' withhold
  4018.  
  4019. Keep in mind that the pattern is actually removed from the parse string when a
  4020. match is found. If the parse string is scanned again from the beginning,the
  4021. length and structure of the string may be different than at the start of the
  4022. parsing process. However,the original source of the string is never modified.
  4023.  
  4024. POSITIONAL MARKERS
  4025.  
  4026. Parsing with positional markers is used whenever the fields of interest are
  4027. known to be in certain positions in a string. In the next example,the records
  4028. being processed contain a variable length field. The starting position and
  4029. length of the field are given in the first part of the record,and a variable
  4030. positional marker is used to extact the desired field.
  4031.  
  4032.     /* records look like:                */
  4033.     /* start:   1-5                    */
  4034.     /* length:  6-10                */
  4035.     /* name:    @(start,length)            */
  4036.     parse value record with 1 start +5 length +5 =start name +length
  4037.  
  4038. The "=start" sequence in the above example is an absolute marker whose value is
  4039. the position paced in the variable start earlier in the scan. The "+length"
  4040. sequence supplies the effective length of the field.
  4041.  
  4042. MULTIPLE TEMPLATES
  4043.  
  4044. It is sometimes useful to specify more than one template with an instruction,
  4045. which can be done by separating the templates with a comma. In this next
  4046. example,the ARG instruction(or PARSE UPPER ARG)is used to access the argument
  4047. strings provided when the program was called. Each template accesses the
  4048. succeeding argument string.
  4049.  
  4050.                 80
  4051.  
  4052.     /* Assume arguments were ('one two',12,sort)    */
  4053.     arg first second,amount,action,option
  4054.  
  4055. The first template consists of the variables first and second,which are set to
  4056. the values "one" and "two,"respectively. In the next two templates amount gets
  4057. the value "12" and action is set to "SORT". The last template consists of the
  4058. variable "option,"which is set to the null string,since only three arguments
  4059. were available.
  4060.  
  4061. When multiple templates are used with the EXTERNAL or PULL source options,each
  4062. additional template requests an additional line of input from the user. In the
  4063. next example two lines of input are read:
  4064.  
  4065.     /* read last,first,and middle names and ssn    */
  4066.     pull last ',' first middle,ssn
  4067.  
  4068. The first input line is expected to have three words,the first of which is
  4069. followed by a comma,which are assigned to the variables last,first,and middle.
  4070. The entire second input line is assigned to the variable ssn.
  4071.  
  4072. Multiple templates can be useful even with a source option that returns the
  4073. identical parse string. If the first template included pattern markers that
  4074. altered the parse string,the subsequent templates could still access the
  4075. original string. Note that subsequent parse strings obtained from the VALUE
  4076. source do not cause the expression to be reevaluated,but only retrieve the
  4077. prior result.
  4078.  
  4079.                 81
  4080.  
  4081.             CHAPTER 9 THE RESIDENT PROCESS
  4082.  
  4083. This chapter describes some of the capabilities of the ARexx resident process,
  4084. a global communications and resources manager. The material presented here is
  4085. directed to the general user;Chapter 10 covers these topics in greater depth
  4086. for software developers who wish to integrate ARexx with other applications
  4087. programs.
  4088.  
  4089. The resident process must be active before any ARexx programs can be run. It
  4090. announces its presence to the system by opening a public message port named
  4091. "REXX,"so applications programs that use ARexx should check for the presence of
  4092. this port. If the port is not open,the user can either be informed that the
  4093. macro processor is not available,or else the applications program can start up
  4094. the resident process. The latter option can be done using the rexxmast command.
  4095.  
  4096. The primary function of the resident process is to launch ARexx programs. When
  4097. an applications program sends a "command" or "function" message to the "REXX"
  4098. port,the resident process creates a new DOS process to execute the program, and
  4099. forwards the invocation message to newly created process. It also creates a new
  4100. instance of the ARexx global data structure,which links together all of the
  4101. structures manipulated by the program.
  4102.  
  4103. In addition to launching programs,the resident process managers various
  4104. resources used by ARexx. These resources include a list of available function
  4105. libraries called the Library List,a list of(name,value)pairs called the Clip
  4106. List,and a list of the currently active ARexx programs. Built-In functions are
  4107. available to manipulate the Library List and Clip List from within an ARexx
  4108. program. Applications programs can modify a resource list either by sending a
  4109. request packet to the resident process or by direct manipulation of the list.
  4110.  
  4111. 9-1 COMMAND UTILITIES
  4112.  
  4113. ARexx is supplied with a number of command utilities to provide various control
  4114. functions. These are executable modules that can be run from the CLI,and should
  4115. reside in the system command(C:)directory for convenience. These commands are
  4116. relevant only when the ARexx resident process is active.
  4117.  
  4118. The functions performed by these utilities may also be available from within an
  4119. applications program. All of the utilities are implemented by sending message
  4120. packets to the resident process,so an application designed to work closely with
  4121. ARexx could easily provide these functions as part of its control menu.
  4122.  
  4123. HI
  4124. Usage:HI
  4125. Sets the global halt flag,which causes all active programs to receive an
  4126. external halt request. Each program will exit immediately unless its HALT
  4127. interrupt has been enabled. The halt flag does not remain set,but is cleared
  4128. automatically after all current programs have received the request.
  4129.  
  4130.                 83
  4131.  
  4132. RX
  4133. Usage:RX name[arguments]
  4134. This command launches an ARexx program. If the specified name includes an
  4135. explicit path,only that directory is searched for the program;otherwise,the
  4136. current directory and the system REXX: device are checked for a program with
  4137. the given name. The optional argument string is passed to the program.
  4138.  
  4139. RXSET
  4140. Usage:RXSET name value
  4141. Adds a(name,value)pair to the Clip List. Name strings are assumed to be in
  4142. mixed case. If a pair with the same name already exists,its value is replaced
  4143. with the current string. If a name without a value string is given,the entry is
  4144. removed from the Clip List.
  4145.  
  4146. RXC
  4147. Usage:RXC
  4148. Closes the resident process. The "REXX" public port is withdrawn immediately,
  4149. and the resident process exits as soon as the last ARexx program finishes. No
  4150. new programs can be launched after a "close" request.
  4151.  
  4152. TCC
  4153. Usage:TCC
  4154. Closes the global tracing console as soon as all active programs are no longer
  4155. using it. All read read requests queued to the console must be satisfied before
  4156. it can be closed.
  4157.  
  4158. TCO
  4159. Usage:TCO
  4160. Open the global tracing console. The tracing output from all active programs is
  4161. diverted automatically to the new console. The console window can be moved and
  4162. resized by the user,and can be closed with the "TCC" command.
  4163.  
  4164. TE
  4165. Usage:TE
  4166. Clears the global tracing flag,which forces the tracing mode to OFF for all
  4167. active ARexx programs.
  4168.  
  4169. TS
  4170. Usage:TS
  4171. Starts interactive tracing by setting the external trace flag,which forces all
  4172. active ARexx programs into interactive tracing mode. Programs will start
  4173. producing trace output and will pause after the next statement. This command is
  4174. useful for regaining control over programs caught in infinite loops or
  4175. otherwise misbehaving. The trace flag remains set until cleared by the TE
  4176. command,so subsequent program invocations will begin executing in interactive
  4177. tracing mode.
  4178.  
  4179.                 84
  4180.  
  4181. 9-2 RESOURCE MANAGEMENT
  4182.  
  4183. Individual ARexx programs manage their internal memory allocation and I/O file
  4184. resources,but some resources need to be available to all programs. The
  4185. management of these global resources is one of the major functions of the
  4186. resident process. Global resources are maintained as doubly-linked lists,in
  4187. keeping with the general design principles of the EXEC operating system. Linked
  4188. lists provide a flexible and open mechanism for resource management,and help
  4189. avoid the built-in limits common with other approaches.
  4190.  
  4191. THE GLOBAL TRACING CONSOLE
  4192.  
  4193. The tracing output from an ARexx program usually goes to the standard output
  4194. stream STDOUT,and is therefore interleaved with the normal output of the
  4195. program. Since this may be confusing at times,a global trace console can be
  4196. opened to display only tracing output. The console can be opened using the tco
  4197. command utility or be sending an RXTCOPN request packet to the resident
  4198. process. ARexx programs will automatically divert their tracing output to the
  4199. new window,which is opened as a standard AmigaDOS console. The user can move it
  4200. and resize it as required.
  4201.  
  4202. The tracing console also serves as the input stream for programs during
  4203. interactive tracing. When a program pauses for tracing input,the input line
  4204. must be entered at the trace console. Any number of programs may use the
  4205. tracing console simultaneously,although it is generally recommended that only
  4206. one program at a time be traced.
  4207.  
  4208. The tracing console can be closed using the tcc command or by sending an
  4209. RXTCCLS request packet to the resident process. The closing is delayed until
  4210. all read requests to the console have been satisfied. Only when all of the
  4211. active programs indicate that they are no longer using the console will it
  4212. actually be closed.
  4213.  
  4214. THE LIBRARY LIST
  4215.  
  4216. The resident process maintains a Library List of the function libraries and
  4217. function hosts currently available to ARexx programs. This list is used to
  4218. resolve all references to external functions. Each entry has an associated
  4219. search priority in the range 100 to -100,with the higher-valued entries being
  4220. searched first until the requested function is found. The list is searched by
  4221. calling each entry,using the appropriate protocol,until the return code
  4222. indicates that the function was found.
  4223.  
  4224. The two types of entities maintained by the list are quite different in some
  4225. respects,but the ultimate way in which a function call is resolved is
  4226. transparent to the calling program. A function library is a collection of
  4227. functions organized as an Amiga shared library,while a function host is a
  4228. separate task that manages a message port. Function libraries are called as
  4229. part of the ARexx interpreter's task context,but calls to function hosts are
  4230. mediated by passing a message packet. The ARexx resident process is itself a
  4231. function host,and is installed in the Library List at a priority of -60.
  4232.  
  4233. The resident process provides addition and deletion operations for maintaining
  4234. the Library List;these operations are performed by sending an appropriate
  4235. message packet. The Library List is always maintained in priority order. Within
  4236. a given priority level any new entries are added to the end of the chain, so
  4237. that entries added first will be searched fist. The priority levels are 
  4238.  
  4239.                 85
  4240.  
  4241. significant if any of the libraries have duplicate function name
  4242. definitions,since the function located further down the search chain could
  4243. never be called.
  4244.  
  4245. FUNCTION LIBRARIES. Each function library entry in the Library List contains a
  4246. library name,a search priority,an entry point offset,and a version number. The
  4247. library name must refer to a standard Amiga shared library residing in the
  4248. system LIBS: directory so that it can be loaded when needed. Function libraries
  4249. can be created and maintained by users or applications developers;Chapter 10
  4250. has information on their design and implementation.
  4251.  
  4252. The "query" function is the library entry point that is actually called by the
  4253. interpreter. It must be specified as an integer offset(e.g. "-30")from the
  4254. library base. The return code from the query call then indicates whether the
  4255. desired function was found;it it was,the function is called with the parameters
  4256. passed by the interpreter and the function result is returned to the caller.
  4257. Otherwise,the search continues with the next entry in the list. In either event
  4258. the library is closed to await the next call.
  4259.  
  4260. A note of caution: not every Amiga shared library can be used as a function
  4261. library. Function libraries must have a special entry point to perform the
  4262. dynamic linking required to access the functions from within ARexx. Each
  4263. library should include documentation providing its version number and the
  4264. integer offset to its "query" entry point.
  4265.  
  4266. FUNCITON HOSTS. The name associated with a function host is the name of its
  4267. public message port. Function calls are passed to the host as a message packet;
  4268. it is then up to the individual host to determine whether the specified
  4269. function name is one that it recognizes. The name resolution is completely
  4270. internal to the host,so function hosts provide a natural gateway mechanism for
  4271. implementing remote procedure calls to other machines in a network.
  4272.  
  4273. THE CLIP LIST
  4274.  
  4275. The Clip List maintains a set of(name,value)pairs that may be used for a
  4276. variety of purposes. Each entry in the list consists of a name and a value
  4277. string,and may be located by name. Since the Clip List is publicly accessible,
  4278. it may be used as a general clipboard-like mechanism for intertask
  4279. communication. In general,the names used should be chosen to be unique to an
  4280. application to prevent collisions with other programs. Any number of entries
  4281. may be posted to the list.
  4282.  
  4283. One potential application for the Clip List is as a mechanism for loading
  4284. predefined constants into an ARexx program. The language definition does not
  4285. include a facility comparable to the "header file" preprocessor in the "C"
  4286. language. However,consider a string in the Clip List of the form
  4287.  
  4288.     pi=3.14159; e=2.718; sqrt2=1.414 ...
  4289.  
  4290. i.e.,a series of assignments separated by semicolons. In use,such a string
  4291. could be retrieved by name using the Built-In function GETCLIP()and then
  4292. INTERPRETed within the program. The assignment statements within the string
  4293. would then create the required constant definitions. The following program
  4294. fragment illustrates the process::
  4295.  
  4296.                 86
  4297.  
  4298.     /* assume a string called "numbers" is available*/
  4299.     numbers=getclip('numbers')    /* case-sensitive */
  4300.     interpret numbers          /* ... assignments*/
  4301.     ...
  4302.  
  4303. More generally,the strings would not be restricted to contain only assignment
  4304. statements,but could include any valid ARexx statements. The Clip List could
  4305. thus provide a series of programs for initializations or other processing
  4306. tasks.
  4307.  
  4308. The resident process supports addition and deletion operations for maintaining
  4309. the Clip List. The names in the(name,value)pairs are assumed to be in mixed
  4310. cases,and are maintained to be unique in the list. An attempt to add a string
  4311. with an existing name will simply update the value string. The name and value
  4312. strings are copied when an entry is posted to the list,so the program that adds
  4313. an entry is not required to maintain the strings.
  4314.  
  4315. Entries posted to the Clip List remain available until explicitly removed. The
  4316. Clip List is automatically released when the resident process exits.
  4317.  
  4318.                 87
  4319.  
  4320.             CHAPTER 10 INTERFACING TO AREXX
  4321.  
  4322. This chapter discusses the issues involved in designing and implementing an
  4323. interface between ARexx and an external applications program. The material
  4324. presented here is directed to software developers,so a high degree of
  4325. familiarity with programming the Amiga in either "C" or assembly-language is
  4326. assumed.
  4327.  
  4328. ARexx can interact with external programs in several ways. The command
  4329. interface is used to communicate with an external program running as a separate
  4330. task in the Amiga's multitasking environment. The interaction takes place by
  4331. passing messages between public message ports,and is in many ways similar to
  4332. the interaction of a program with Intution,the Amiga's window and menu manager.
  4333. The command interface provides both a means of sharing data and a method of
  4334. controlling an applications program.
  4335.  
  4336. Function libraries provide a mechanism for calling external code as part of an
  4337. ARexx program's tasks context. The linkages for such calls are established
  4338. dynamically at run time rather than when the program is linked,so each function
  4339. library must include an entry point to match function names with the address of
  4340. the function to be called.
  4341.  
  4342. Function hosts are external tasks that manage a public message port for
  4343. communicating with ARexx or other programs. Both function hosts and function
  4344. libraries are managed by the Library List,which provides a prioritized search
  4345. mechanism for resolving function names. Function hosts may be used as a gateway
  4346. into a metwork to provide a remote procedure call facility. ARexx imposes no
  4347. constraints on the internal operations of a function host,except to require
  4348. that message packets be returned with an appropriate code.
  4349.  
  4350. The resident process acts as the hub for communications between ARexx and
  4351. external entities. It opens and manages a public message port named "REXX," and
  4352. provides a number of support services. Note that the resident process is itself
  4353. a "host application" whose function it is to launch ARexx programs and maintain
  4354. global resources. The activation structures for all ARexx programs are linked
  4355. into a list maintained by the resident process,and in principle their compete
  4356. internal states are accessible to external programs.
  4357.  
  4358. The ARexx interpreter is structured as an Amiga shared library and includes
  4359. entry points specifically designed to help implement an interface to ARexx.
  4360. Functions are available to create and delete message packets,argument
  4361. strings,and other resources. Software developers are rged to use these library
  4362. routines whenever possible,as they provide "safe" access to the internal
  4363. structures. The ARexx Systems Library functions are documented in Appendix C.
  4364. The distribution disk contains the INCLUDE files required to required to work
  4365. with the library and data structures.
  4366.  
  4367.                 89
  4368.  
  4369. 10-1 BASIC STRUCTURES
  4370.  
  4371. Most developers will need to work with only two of the data structures used by
  4372. ARexx. The RexxArg structure is used for all of the strings manipulated by the
  4373. interpreter. It is usually passed as an argstring,a pointer offset from the
  4374. structure base that may be treated like an ordinary string pointer. The RexxMsg
  4375. structure is an extension of an EXEC Message,and is the message packet used for
  4376. all communications with external programs.
  4377.  
  4378. ARGSTRINGS. All ARexx strings are maintained as RexxArg structures,which are
  4379. diagrammed in Table 10.1 below. Note that his actually a variable-length
  4380. structure allocated for each specific string length. String parameters are sent
  4381. in the form of argstrings,a pointer to the string buffer area of the RexxArg
  4382. structure. The string in the stucture is always given a trailing null byte,so
  4383. that external programs can treat argstrings like a pointer to a null-terminated
  4384. string. Additional data about the string(its length,hash code,and attributes)
  4385. are available at negative offsets from the argstring pointer.
  4386.  
  4387.             Table 10.1 The RexxArg Structure
  4388.  
  4389.         STRUCTURE RexxArg,0
  4390.         LONG    ra_Size        ; allocated length
  4391.         UWORD    ra_Length    ; length of string
  4392.         UBYTE    ra_Flags    ; attribute flags
  4393.         UBYTE    ra_Hash        ; hash code
  4394.         STRUCT    ra_Buff,8    ; buffer (argstring points here)
  4395.  
  4396. Library functions are available to create and delete argstrings,and for
  4397. converting integers into argstring format. The function CreateArgstring()
  4398. allocates a structure and copies a string into it,and returns an argstring
  4399. pointer to the structure. The function DeleteArgstring()can be used to release
  4400. an argstring when it is no longer needed.
  4401.  
  4402. MESSAGE PACKETS. All communications between ARexx and external programs are
  4403. mediated with with message packets,whose structure is diagrammed in Table 10.2
  4404. below. Functions are provided in the ARexx Systems Library to create,
  4405. initialize,and delete these message packets. Each packet sent from ARexx to an
  4406. external program is marked with a special pointer in its name field. This can
  4407. be used to distinguish the message packets from those belonging to other
  4408. programs,in case a message port is being shared.
  4409.  
  4410. Message packets are created using the CreateRexxMsg()function,and can be
  4411. released using the DeleteRexxMsg(). Note that the message packets passed by
  4412. ARexx to a host application(as a command,for instance)are identical to the
  4413. packets the host would use to invoke an ARexx program. This commonality of
  4414. design means that only one set of functions is needed to create and delete
  4415. message packets,and that external programs can use the same routines that the
  4416. interpreter uses to handle the packets.
  4417.  
  4418. RESOURCE NODES. A somewhat higher-level data structure called a "resource node"
  4419. (a RexxRsrc structure)is used extensively within ARexx to maintain resource
  4420. lists. These nodes are variable-length structures that include the total
  4421. allocated length as a field within the node,and that also provide for an
  4422. "auto-delete" function. This latter capability allows the address of a clean-up
  4423.  
  4424.                 90
  4425.  
  4426. function to be associated with the node so that an entire(possibly
  4427. inhomogeneous)list of resource nodes can be deallocated with a single function
  4428. call.
  4429.  
  4430.             Table 10.2 The RexxMsg Structures
  4431.  
  4432.         STRUCTURE RexxMsg,MN_SIZE
  4433.         APTR    rm_TaskBlock    ; global pointer
  4434.         APTR    rm_LibBase    ; library pointer
  4435.         LONG    rm_Action    ; command code
  4436.         LONG    rm_Result1    ; primary result
  4437.         LONG    rm_Result2    ; secondary result
  4438.         STRUCT    rm_Args,16*4    ; arguments (ARGO-ARG15)
  4439.                      ;  the extension area
  4440.         APTR    rm_PassPort    ; forwarding port
  4441.         APTR    rm_CommAddr    ; host address
  4442.         APTR    rm_FileExt    ; file extention
  4443.         LONG    rm_Stdin    ; input stream
  4444.         LONG    rm_Stdout    ; output steam
  4445.         LONG    rm_avail    ; reserved
  4446.         LABEL    rm_SIZEOF    ; 128 bytes
  4447.  
  4448. 10-2 DESIGNING A COMMAND INTERFACE
  4449.  
  4450. The minimal command interface between ARexx and an applications program
  4451. requires only a public message port and a routine to process the commands
  4452. received. For most host applications this will require little extra machinery,
  4453. as the program will probably already have several message ports for key and
  4454. menu events,timer messages,and so on. Processing the command strings should be
  4455. relatively straightforward for command-oriented applications. Hosts that are
  4456. entirely menu-driven will require somewhat more additional programming,unless
  4457. commands are supported only as simulated menu events. The specific choice of
  4458. which commands to support is always left up to the applications designer,as
  4459. ARexx imposes no restrictions on the structure of the commands that can be
  4460. issued.
  4461.  
  4462. The basic sequence of events in the command interface begins when the host
  4463. sends a command invocation message to the ARexx resident process. This is
  4464. usually in response primitives supported by the host. When the resident process
  4465. receives the message packet,it spawns a new DOS process the run the macro
  4466. program. The command line is parsed to extract the command token(the first
  4467. word),and the interpreter searches for a file that matches the command name.
  4468.  
  4469. Once a macro program file has been found,it is executed by the interpreter and
  4470. (usually)results in one or more commands being issued back to the host
  4471. application's public port. The macro program waits while each command is
  4472. processed by the host,and takes appropriate actions if the return code
  4473. indicates that an error occurred. Eventually the macro program finishes and
  4474. returns the invocation message packet back to the host.
  4475.  
  4476. Error handling is an important consideration in the interface design. Macro
  4477. programs must receive return codes so that processing actions can be altered
  4478. when errors occur.
  4479.  
  4480.                 91
  4481.  
  4482. Normally,the host application should not return a message packet until the
  4483. command has been processed and its error status in known. Hosts that support
  4484. two streams of commands(from the user and from the command interface)will need
  4485. a flag to indicate the source of each command. Errors in user commands might
  4486. normally be reported on the screen,but errors in ARexx commands must be
  4487. reported by setting the result field in the message packet.
  4488.  
  4489. Return codes should generally be chosen to follow the model of an error
  4490. severity level,with small integers representing relatively harmless conditions
  4491. and larger values indicating progressively more severe errors. This will allow
  4492. a characteristic failure level to be established within a macro program,so that
  4493. insignificant errors can be ignored. The choice of the specific return code
  4494. values is left to the applications designer.
  4495.  
  4496. RECEIVING COMMAND MESSAGES
  4497.  
  4498. Each host application must open a public message port to support the command
  4499. interface. When a macro program issues a command to the host,a message packet
  4500. containing the command is sent to this public port. The structure of these
  4501. message packets is shown in Table 10.2. The rm_Action field will be set to
  4502. RXCOMM,and the ARGO parameter slot will contain the command as an argstring
  4503. pointer. Parameter slots ARG1-ARG15 are not used for command messages. Two
  4504. other fields are potentially of interest: the rm_RexxTask field contains a
  4505. pointer to the global data structure for the program that issued the command,
  4506. and the rm_LibBase field has the ARexx library base address. The fields in the
  4507. extension area may also be of interest to the host program;these are described
  4508. later on. Except for setting the result fields rm_Result1 and rm_Result2,the
  4509. host application should not alter the message packet.
  4510.  
  4511. RESULT FIELDS
  4512.  
  4513. When the host program finishes processing the command,it must set the primary
  4514. result field rm_Result1 to an error severity level or zero if no errors
  4515. occurred. This is the field which will be assigned to the special variable RC
  4516. in the macro program. The secondary result field rm_Result2 should be set to
  4517. zero unless a result string(as described below)is being returned. The packet
  4518. can then be returned to the sender using the EXEC function ReplyMsg().
  4519.  
  4520. In some cases a macro program may request a result string by setting the
  4521. RXFB_RESULT modifier bit in the command code. If possible,the host application
  4522. should then return the result as an argstring pointer in the secondary result
  4523. field rm-Result2. A result string should only be returned if explicitly
  4524. requested and if no errors occurred during the call(rm_Result1 set to zero).
  4525. Failure to observe these rules will result either in memory loss or in
  4526. corruption of the system free-memory list.
  4527.  
  4528. MULTIPLE HOST PROCESSES
  4529.  
  4530. Many applications programs support concurrent activities on several sets of
  4531. data. For example,most text editors allow several files to be edited at once. A
  4532. command issued from a particular instance of the editor might invoke an ARexx
  4533. macro program,so clearly any commands issued from that macro would have to be
  4534. directed to the correct instance of the editor. ARexx provides for this by
  4535.  
  4536.                 92
  4537.  
  4538. allowing the applications program to declare an initial host address when a
  4539. program is invoked. A separate message port would be opened for each instance
  4540. of the host application,and this port would be named as the initial host
  4541. address for all invocations from that instance. In the example above,if the
  4542. editor opened two ports named "MyEdit1" and "MyEdit2,"then programs invoked by
  4543. the "MyEdit1" instance would send commands back to the "MyEdit1" port.
  4544.  
  4545. MULTIPLE MESSAGE PORTS. Host applications are not limited to having a single
  4546. message port for commands. If several different kinds of commands are to be
  4547. received,it might be appropriate to set up more than one port. Macro programs
  4548. would then use the ADDRESS instruction to direct commands to the appropriate
  4549. port. The different ports could be used simultaneously,since ARexx programs
  4550. execute as separate tasks.
  4551.  
  4552. 10-3 INVOKING AREXX PROGRAMS
  4553.  
  4554. ARexx programs are invoked by sending a message packet to the resident process.
  4555. Programs may be invoked as either a command or as a function. The command mode
  4556. of invocation is generally simpler,as it requires setting only a few fields in
  4557. the message packet.
  4558.  
  4559. MESSAGE PACKETS
  4560.  
  4561. The structure of the message packet supported by ARexx is shown in Table 10.2.
  4562. This structure provides fields for passing arguments and for specifying
  4563. overrides to various internal defaults. The packets are cleared(set to 0)when
  4564. allocated,and the client-supplied fields are never altered by ARexx. Message
  4565. packets can be reused after being returned,and generally only one is required.
  4566.  
  4567. COMMAND(ACTION)CODE. The rm_Action field of the message packet determines the
  4568. mode of invocation. It can be set to either RXCOMM or RXFUNC for command or
  4569. function mode,respectively. Several modifier flags can be used with the command
  4570. code;these are described later in this chapter.
  4571.  
  4572. ARGUMENT STRINGS. Command strings,function names,and argument strings must be
  4573. supplied as argstrings. Strings can be conveniently packaged into argstrings
  4574. using the CreateArgstring()library function,which takes a string pointer and a
  4575. length as its arguments. Argstrings point to a null-terminated string and may
  4576. be treated like an ordinary string pointer in most cases. In principle,a host
  4577. application could build the argstrings directly,but since the strings must
  4578. remain unchanged for the duration of a ARexx program,the host might need to
  4579. maintain many such structures.
  4580.  
  4581. The argstrng pointer returned by CreateArgstring()is installed in the
  4582. appropriate parameter slot of the message package:ARGO for the command string
  4583. or function name,and ARG1-ARG15 for argument strings. Argstrings can be
  4584. recycled after a packet has returned by calling the DeleteArgstring() function.
  4585.  
  4586. SENDING THE PACKET. Once the required fields have been filled in,the host
  4587. application can send the packet to the "REXX" public port using the EXEC
  4588. function PutMsg(). The address of the "REXX" port can be obtained by a call to
  4589. the FindPort()function,but this address should not be cached internally,since
  4590. the port could close at any time. To be absolutely safe,the calls to FindPort()
  4591. and PutMsg()should be bracketed by calls to the EXEC routines Forbid()and
  4592. Permit(). This will exclude the slight possibility that the message port could
  4593. close in the few microseconds before the message packet is actually sent to the
  4594. port address.
  4595.  
  4596. After sending the packet the host can return to its normal processing,since the
  4597. macro program will execute as a separate task. In most cases it will be
  4598. advisable to "lock-out" further user commands while the ARexx program is
  4599. running,to preserve te integrity of any shared data structures that may be
  4600. accessed externally.
  4601.  
  4602. COMMAND INVOCATIONS
  4603.  
  4604. In the command mode of invocation the host supplies a command string consisting
  4605. of a name token followed by an argument string. ARexx parses the string to
  4606. extract the command name,which is usually the name of a program file. The
  4607. default action is to use the remainder of the command string as the(single)
  4608. argument string for the program. This may be overridden by requesting command
  4609. tokenization,which is done by setting the RXFB_TOKEN modifier flag in the
  4610. action code of the message packet. In this case the entire command string will
  4611. be parsed,and the program may have many argument strings.(There is no limit to
  4612. the number of arguments that may be derived from the command string,since they
  4613. don't have to fit into the parameter slots of the message packet.)
  4614.  
  4615. The parsing process uses "white space" (blanks,tabs,etc.)as the token
  4616. separators,and has a several special features.
  4617.  
  4618. QUOTING CONVENTION. Either single(')or double(")quotes may be used to surround
  4619. items that include "white space" and would otherwise be separated during
  4620. parsing. Single quotes may appear within a double-quote-delimited token,and
  4621. vice versa;however,double-delimiter sequences are not accepted. The quotes are
  4622. removed from the parsed token. An "implicit" quote at the end of the string is
  4623. also recognized. If the command string ends before the closing delimiter has
  4624. been found,the null byte is accepted as the final delimiter. For example,
  4625.     look.rexx "Now is the time" "can't ou see
  4626.  
  4627. is a command with the two arguments strings "Now is the time" and "can't you
  4628. see"(but without the quotes.)
  4629.  
  4630. STRING FILES. If the command name(the first token of the string)is quoted,it is
  4631. assumed to be a "string file" --an ARexx program in a string,rather than the
  4632. name of a disk file. This is a convenient way to run very brief programs,
  4633. although programs of any length may be stored this way. If command tokenization
  4634. has not been specified,the remainder of the string is not scanned and no quote
  4635. characters are removed. In this case the quoting convention isuseful only for
  4636. indicating "string file" programs. The entire command string can be declared as
  4637. a "string file" by setting the RXFB_STRING modifier flag of the action code.
  4638. When this flag is set,no parsing at all is applied to the command.
  4639.  
  4640. RESULT STRING. Command invocations do not usually request a result string,but
  4641. can do so by setting the RXFB_RESULT modifier flag. The host application must
  4642. be prepared to recycle the returned result string once it is no longer needed.
  4643.  
  4644.                 94
  4645.  
  4646. FUNCTION INVOCATIONS
  4647.  
  4648. In a function invocation the host application supplies a function name string
  4649. and from 0 to 15 argument strings. The name string is used to locate an
  4650. external program file and may include directory specifiers and a file
  4651. extension. The actual argument count(not including the name string)must be
  4652. placed in the low-order byte of the command code.
  4653.  
  4654. This mode of invocation is normally used when a result string is expected and
  4655. the argument strings are conveniently available. Note that a result does not
  4656. have to be requested,however.
  4657.  
  4658. RESULT STRINGS. Function invocations request a result string by setting the
  4659. RXFB_RESULT modifier flag bit. If no errors occurred and a result string was
  4660. requested,the secondary result field in the returned packet will be a pointer
  4661. to the result string. However,if the program exited without supplying a result,
  4662. the secondary field will be zero.
  4663.  
  4664. STRING FILES. The function name argument may specify a "string file" rather
  4665. than the name of a filing system object. This is indicated by setting the
  4666. RXFB_STRING modifier flag.
  4667.  
  4668. SEARCH ORDER
  4669.  
  4670. The search for a program file matching a command or function name is normaly a
  4671. two-step process. For each directory to be checked,a search is made first with
  4672. the current file extension appended to the name string. If this search fails,
  4673. the second search uses the unmodified name string. The first step is skipped if
  4674. the command or function name includes an explicit file extension.
  4675.  
  4676. The default file extension is ".rexx,"but this can be changed by supplying a
  4677. file extension string in an extended message packet. Host applications will
  4678. usually specify a file extension,since it provides a convenient way to
  4679. distinguish the macro programs that are specific to that application. Refer to
  4680. the section on Extension Fields for further details.
  4681.  
  4682. The search path for a program depends on the way the program name was
  4683. specified. If an explicit device or directory specification precedes the
  4684. program name,only that directory will be searched. For example,the command-
  4685. level invocation of "rx df0:s/test" will search only the df0:s directory for a
  4686. file named test.rexx or test. If the program name does not include a path,the
  4687. search path begins with the current directory and proceeds to the system REXX:
  4688. directory. To further the above example,invoking the program as "rx test 1 2 3"
  4689. would search for the files test.rexx,test,REXX:test.rexx,and REXX:test,in that
  4690. order.
  4691.  
  4692. If an ARexx program cannot be found,one alternative action may be taken. If the
  4693. rm_PassPort field of an extended packet was supplied,the message packet is
  4694. passed along to that port,which might be the next process in a search chain.
  4695. Otherwise the message is returned with a "Program not found"error indication
  4696. (error code 1.)
  4697.  
  4698.                 95
  4699.  
  4700. EXTENSION FIELDS
  4701.  
  4702. The RexxMsg structure includes several "extension fields" that can be used to
  4703. override various defaults when a program is invoked. These extension fields can
  4704. be filled in selectively,and only the non-zero values will override the
  4705. corresponding default. ARexx never modifies the extension area.
  4706.  
  4707. Host applications should supply values for the file extension and host address
  4708. fields of the message packet. The file extension affects which program files
  4709. will match a given command name,and allows macro programs specific to the host
  4710. to be given distinctive names. The host address must refer to a public message
  4711. port,and will usually indicate the host's own port. Any appropriate(but usually
  4712. short)strings can be chosen for these values. Oftern,the name of the
  4713. applications program itself can be used as its host address and file extension.
  4714.  
  4715. PASSPORT. The rm_PassPort field allows the search for a program to be "passed
  4716. along" to another messsage port after checking for an ARexx program. If the
  4717. command or function name doesn't resolve to an ARexx program,the message packet
  4718. is forwarded to the message port specified as the PassPort. This allows
  4719. applications to maintain control over the search order for external program
  4720. files.
  4721.  
  4722. Note that the rm_PassPort field must be the actual address of a message port,
  4723. rather than a name string. The PassPort therefore does not have a public port,
  4724. but the port should be a secured resource,since the message is sent directly to
  4725. this address without checking to see whether it is a valid message port.
  4726.  
  4727. HOST ADDRESS. The rm_ComAddr field overrides the default initial host address,
  4728. which is "REXX." The host address is the name of the messsage port to which
  4729. commands will be directed,and is supplied as a pointer to a null-terminated
  4730. string. Applications that support multiple instances of user data will usually
  4731. create a separate message port for each instance. The name of this port would
  4732. then be supplied as the host address for any commands issued from that
  4733. instance.
  4734.  
  4735. FILE EXTENSION. The rm_FileExt field is used to override the default file
  4736. extension for ARexx programs,which is "REXX". Host applications can use the
  4737. file extension to distinguish the names of the macro programs specific to that
  4738. application. It is supplied as a pointer to a null-terminated string.
  4739.  
  4740. INPUT AND OUTPUT STREAMS. The default input and output steams for an ARexx
  4741. program are inherited from the host application's process structure,if the host
  4742. is a process rather than just a task. One or both of these streams may be
  4743. overridden by supplying an appropriate value in the rm-Stdin or rm_stdout
  4744. fields. The values supplied must be valid DOS filehandles,and must not be
  4745. closed while the program is executing. The steams are installed directly into
  4746. the program's process structure,replacing the prior values.
  4747.  
  4748. The output stream is also used as the default tracing stream for the program.
  4749. If interactive tracing is to be used in a program,the output stream should
  4750. refer to a console device,since it will be used for input as well.
  4751.  
  4752.                 96
  4753.  
  4754. In the event than an ARexx program is invoked by an EXEC task,rather than by an
  4755. DOS process,the extension field streams are the only way that the launched
  4756. program can be given default I/O streams.
  4757.  
  4758. INTERPRETING THE RESULT FIELDS
  4759.  
  4760. The message packet that invoked an ARexx program is returned to the client when
  4761. the program finishes. The two result fields will contain error codes or
  4762. possibly a result string. The interpretation of the result fields depends
  4763. partly on the mode of invocation. If the primary result field rm_Result1 is
  4764. zero,the program executed normally and the secondary field rm_Result2 will
  4765. contain a pointer to a result string,assuming that one was requested(and
  4766. available.)
  4767.  
  4768. If the primary result is non-zero,it represents either an error severity level
  4769. or else the return code from a command invocation. The two cases can be
  4770. distinguished by examining the secondary result. If the secondary field is also
  4771. non-zero,an error occurred and the secondary field is an ARexx error code. If
  4772. the secondary result is zero,then the primary result is the return code passed
  4773. by an "EXIT rc" or "RETURN rc" instruction in the program. The application
  4774. program can use this return code either as an error indication or to initiate
  4775. some particular processing action.
  4776.  
  4777. Result strings are always returned as an argstring and become the property(that
  4778. is,responsibility)of the host. When the string is no longer needed,it can be
  4779. released using the DelArgstring() function.
  4780.  
  4781. Errors occurring in macro programs should usually be reported to the user.
  4782. Explanatory messages are available for all ARexx error codes,and can be
  4783. obtained by calling the ARexx Systems Library function ErrorMsg().
  4784.  
  4785. 10-4 COMMUNICATING WITH THE RESIDENT PROCESS
  4786.  
  4787. All communications with the resident process are handled by passing message
  4788. packets,which were previously diagrammed in Table 10.2. The packet has a
  4789. command field that describes the action to be performed and parameter fields
  4790. that are specific to the command. Message packets are processed as they are
  4791. received,and are then either returned to the sender or passed along to another
  4792. process(in the case of a program invocation.) The packet includes two result
  4793. fields that are used to return error codes or result strings. The parameter
  4794. fields of the message packet may contain either(long)integer values or pointers
  4795. to argument strings. String arguments are assumed to be argstring pointers
  4796. unless otherwise specified.
  4797.  
  4798. COMMAND(ACTION)CODES
  4799.  
  4800. The command codes that are currently implemented in the resident process are
  4801. described below. Commands are listed by their mnemonic codes,followed by the
  4802. valid modifier flags. The final code value is always the logical OR of the code
  4803. value and all of the modifier flags selected. The command code is installed in
  4804. the rm_Action field of the message packet.
  4805.  
  4806. USAGE: RXADDCON [RXFB_NONRET]
  4807. This code specifies an entry to be added to the Clip List. Parameter slot ARGO
  4808. points to the name string,slot ARG1 points to the value string,and slot ARG2
  4809. contains the length of the value string.
  4810.  
  4811.                 97
  4812.  
  4813. The name and value arguments do not need to be argstrings,but can be just
  4814. pointers to storage areas. The name should be a null-terminated string,but the
  4815. value can contain arbitrary data including nulls.
  4816.  
  4817. USAGE: RXADDFH [RSFB_NONRET]
  4818. This action code specifies a function host to be added to the Library List.
  4819. Parameter slot ARGO points to the(null-terminated)host name string,and slot
  4820. ARG1 holds the search priority for the node. The search priority should be an
  4821. integer between 100 and -100 inclusive;the remaining priority ranges are
  4822. reserved for future extensions. If a none already exists with the same name,the
  4823. packet is returned with a warning level error code. Note that no test is made
  4824. at this time as to whether the host port exists.
  4825.  
  4826. USAGE:RXADDLIB [RXFB_NONRET]
  4827. This code specifies an entry to be added to the Library List. Parameter slot
  4828. ARGO points to a null-terminated name string referring either to a function
  4829. library or a function host. Slot ARG1 is the priority for the node and should
  4830. be an integer between 100 and -100 inclusive;the remaining priority ranges are
  4831. reserved for future extensions. Slot ARG2 contains the entry oint offset and
  4832. slot ARG3 is the library version number. If a node already exists with the same
  4833. name,the packet is returned with a warning level error code. Otherwise,a new
  4834. entry is added and the library or host becomes available to ARexx programs.
  4835. Note that no test is made at this time as to whether the library exists and can
  4836. be opened.
  4837.  
  4838. USAGE:RXCOMM [RXFB_TOKEN] [RXFB_STRING] [RXFB_RESULT] [RXFB_NOIO]
  4839. Specifies a command-mode invocation of an ARexx program. Parameter slot ARGO
  4840. must contain an argstring ointer to the command string. The RXFB_TOKEN flag
  4841. specifies that the command line is to be tokenized before being passed to the
  4842. invoked program. The RXFB_STRING flag bit indicates that the command string is
  4843. a "string file." Command invocations do not normally return result strings,but
  4844. the RXFB_RESULT flag can be set if the caller is prepared to handle the cleanup
  4845. associated with a returned string. The RXFB_NOIO modifier suppresses the
  4846. inheritance of the host's input and output streams.
  4847.  
  4848. USAGE:RXFUNC [RXFB_RESULT] [RXFB_STRING] [RXFB_NOIO] argcount
  4849. This command code specifies a function invoction. Parameter slot ARGO contains
  4850. a pointer to the function name string,and slots ARG1 through ARG15 point to the
  4851. argument strings,all of which must be passed as argstrings. The lower byte of
  4852. the command code is the argument count;this count excludes the function name
  4853. string itself. Function calls normally set the RXFB_RESULT flag,but this is not
  4854. mandatory. The RXFB_STRING modifier indicates that the function name string is
  4855. actually a "string file". The RXFB_NOIO modifier suppresses the inheritance of
  4856. the host's input and output streams.
  4857.  
  4858. USAGE:RXREMCON [RXFB_NONRET]
  4859. This code requests that an entry be removed from the Clip List. Parameter slot
  4860. ARGO points to the null-terminated name to be removed. The Clip List is
  4861. searched for a node matching the supplied name,and if a match is found the list
  4862. node is removed and recycled. If no match is found the packet is returned with
  4863. a warning error code.
  4864.  
  4865. USAGE:RXREMLIB [RXFB_NONRET]
  4866. This command removes a Library List entry. Parameter slot ARGO points to the
  4867. null terminated string specifying the library to be removed. The Library List
  4868. is searched for a node matching the library name,and if a match is found the
  4869.  
  4870.                 98
  4871.  
  4872. node is removed and released. If no match is found the packet is returned with
  4873. a warning error code. The libary node will not be removed if the library is
  4874. currently being used by an ARexx program.
  4875.  
  4876. USAGE:RXTCCLS [RXFB_NONRET]
  4877. This code requests that the global tracing console be closed. The console
  4878. window will be closed immediately unless one or more ARexx programs are waiting
  4879. for input from the console. In this event,the window will be closed as soon as
  4880. the active programs are no longer using it.
  4881.  
  4882. USAGE:RXTCOPN [RXFB_NONRET]
  4883. This command requests that the global tracing console be opened. Once the
  4884. console is open,all active ARexx programs will divert their tracing output to
  4885. the console. Tracing input(for interactive debugging)will also be diverted to
  4886. the new console. Only one console can be opened;subsequent RXTCOPN requests
  4887. will be returned with a warning error message.
  4888.  
  4889. MODIFIER FLAGS
  4890.  
  4891. Command codes may include modifier flags to select various processing options.
  4892. Modifier flags are specific to certain commands,and are ignored otherwise.
  4893.  
  4894. RXFB_NOIO. This modifier is used with the RXCOMM and RXFUNC command codes to
  4895. suppress the automatic inheritance of the host's input and output streams.
  4896.  
  4897. RXFB_NONRET. Specifies that the message packet is to be recycled by the
  4898. resident process rather than being returned to the sender. This implies that
  4899. the sender doesn't care about whether the requested action succeeded,since the
  4900. returned packet provides the only means of acknowledgement. Messge packets are
  4901. released using the library function DeleteRexxMsg().
  4902.  
  4903. RXFB_RESULT. This modifer is valid with the RXCOMM and RXFUNC commands,and
  4904. requests that the called program return a result string. If the program
  4905. EXITs(or RETURNs)with an expression,the expression result is returned to the
  4906. caller as an argstring. It is then the caller's responsibility to release the
  4907. argstring when it is no longer needed;this can be done using the library
  4908. function DeleteArgstring().
  4909.  
  4910. RXFB_STRING. This modifer is valid with the RXCOMM and RXFUNC command codes. It
  4911. indicates that the command or function argument(in slot ARGO)is a "string file"
  4912. rahter than a file name.
  4913.  
  4914. RXFB_TOKEN. This flag is used with the RXCOMM code to request that the command
  4915. string be completely tokenized before being passed to the invoked program.
  4916. Programs invoked as commands normally have only a single argument string. The
  4917. tokenization process uses "white space" to separate the tokens,except within
  4918. quoted strings. Quoted strings can use either single or double quotes,and the
  4919. end of the command string(a null character)is considered as an implicit closing
  4920. quote.
  4921.  
  4922.                 99
  4923.  
  4924. RESULT FIELDS
  4925.  
  4926. The resident process uses the standard command-level conventions for the
  4927. primary return code installed in rm_Result1. Minor or warning errors are
  4928. indicated by a value of 5,and more serious errors are returned as values of 10
  4929. or 20. The secondary result field rm-Result2 will either be zero or an ARexx
  4930. error code if applicable.
  4931.  
  4932. Note that RXCOMM and RXFUNC messages are returned directly by the invoked macro
  4933. program,rathe than by the residen process.
  4934.  
  4935. 10-5 EXTERNAL FUNCTION LIBRARIES
  4936.  
  4937. ARexx supports external function libraries as a mechanism for user-defined
  4938. extensions to the language. Function libraries may be written and maintained by
  4939. users or applications developers.
  4940.  
  4941. DESIGN CONSIDERATIONS
  4942.  
  4943. There are several different purposes for which a function library might be
  4944. designed. In the simplest case,a library could be used to extend the string
  4945. manipulation or mathematical capabilities of the language by defining new
  4946. functions. Such a library could be entirely self-contained or might call other
  4947. system libraries to perform specific operations.
  4948.  
  4949. Another alternative would be to build a library that interacts closely with an
  4950. external applications program. This could allow specific operations in the host
  4951. application to be performed as function calls rather than as commands. There
  4952. are several advantages to this approach,as it avoids the need to parse command
  4953. strings and does not require the multiple task context changes associated with
  4954. message-passing. The library might include entry points for specific operaions
  4955. as well as functions to support processing required by the applications
  4956. program.
  4957.  
  4958. Function libraries can also serve as bridges to other system or applications
  4959. libraries. For example,if a program needed to call the functions in a graphics
  4960. library,a bridge library could be built to match the function names in the
  4961. program with the appropriate entry point in the graphics library. A related
  4962. possibility would be to use ARexx as a test driver for a program under
  4963. development. Once the query table and parameter passing mechanisms for the
  4964. function library have been built,new routines under development could be tested
  4965. by just adding a table entry. Since building test programs is ofter very time-
  4966. consuming,the flexibility and interactive debugging capabilities of ARexx make
  4967. it an attractive alternative to compiled languages like "C."
  4968.  
  4969. Regardless of the intended application,all function libraries share a common
  4970. structure. The initial design follows that of the standard EXEC shared library,
  4971. with the three required entry points Open,Close,and Expunge,plus a reserved
  4972. slot. The library must also have a "query" entry point,which serves to match
  4973. the name supplied by ARexx with the intended function. Typically,this will
  4974. consist of a table of function names and a routine to search for the specified
  4975. one.
  4976.  
  4977. REENTRANCY. Functions libraries should be designed to be fully reentrant,since
  4978. any number of ARexx programs may be running at any time. If this is not
  4979. feasible due to other design constraints,the query function should include a
  4980. lockout mechanism to prevent multiple calls to the library routines.
  4981.  
  4982.                 100
  4983.  
  4984. CALLING CONVENTION
  4985.  
  4986. The library's query function will be called from the interpreter's context with
  4987. the address of a message packet in register A0 and the library base in A6. The
  4988. structure of the message packet is the same as that in Table 10.2,but note that
  4989. although a message packet is used to carry the arguments,it is not queued at a
  4990. message port and does not need to be unlinked. The name of the function to be
  4991. called is carried in the ARGO parameter slot. The query function must search
  4992. for this function name and,if the name cannot be found,must return an error
  4993. code of 1("Program not found")in register D0. The library will then be closed
  4994. and the search continued in the next function library. The query function
  4995. should not modify any fields within the message packet,as it must be passed
  4996. along to the next library until the function is located.
  4997.  
  4998. PARAMETER CONVERSION
  4999.  
  5000. Once the requested function has been found,the query funcion may need to
  5001. transform the parameters passed by ARexx into the form expected by the
  5002. function. Whether the parameter strings need to be converted depends on how
  5003. they are to be used. In some cases it may be sufficient just to foward a
  5004. pointer to the message packet to the called function,while in other cases the
  5005. query function may need to load parameters into registers or to perform
  5006. conversion operations. The parameters in ARG1-ARG15 are always passed as
  5007. argstrings,and may be treated like a pointer to a null-terminated string.
  5008. Further attributes are stored at negative offsets from the argstring pointer,
  5009. and may be helpful in working with the string.
  5010.  
  5011. Numeric quantities are passed as strings of ASCII characters and will need to
  5012. be converted to integer or floating-point format if arithmetic calculations are
  5013. to be performed. The ARexx System Library includes a limited set of functions
  5014. to do parameter conversions.
  5015.  
  5016. The actual parameter count can be obtained from the low-order byte of the
  5017. rm_Action field in the message packet. The count never includes the function
  5018. name itself(in ARGO),but does include arguments specified as "defaults." Such
  5019. arguments will have a zero value in the corresponding parameter slot.
  5020.  
  5021. Note that the parameter block of the message packet,containing the fields
  5022. ARG0-ARG15,is structured like the argument array expected by the main(argc,
  5023. argv)function of a "C" program. This suggests a simple way that a function
  5024. library could provide a bridge to a series of "C" programs. The query function
  5025. would need only to determine the address of the called function,and then push
  5026. the parameter block address and argument count onto the program stack.
  5027.  
  5028. RETURNED VALUES
  5029.  
  5030. Each library function must return an error code and a value string. The error
  5031. code is returned in register D0,and should be 0 if no errors occurred. The
  5032. value string must be returned as an argstring pointer in register A1,unless D0
  5033. indicates that an error occurred during the call. The mechanisms for creating
  5034. the proper return values can be made part of the query function,so that all
  5035. functions in the library share a common return path.
  5036.  
  5037.                 101
  5038.  
  5039. 10-6 DIRECT MANIPULATION OF DATA STRUCTURES
  5040.  
  5041. All of the data structures maintained by the resident process are built into
  5042. the ARexx Systems Library base and are therefore accessible to external
  5043. programs. The Task List in the RexxBase structure links the global data
  5044. structures for all currently active ARexx programs. This linkage uses the node
  5045. contained in the message port of the RexxTask structure,rather than at the head
  5046. of the structure. The RexxTask structure is the global data structure and
  5047. initial storage environment for the ARexx program,and all descendant storage
  5048. environments are linked into the Environment List. The linkage of internal data
  5049. structures is such that the complete internal state of all ARexx programs can
  5050. be reached starting from the library base pointer.
  5051.  
  5052. Two library functions,LockRexxBase() and UnlockRexxBase(),are provided to
  5053. mediate access to the global structures. The structure base should be locked
  5054. before reading any of the data items or traversing any of the lists. The
  5055. present version of these functions provides only a global lock,but future
  5056. extensions will allow individual resources to be locked.
  5057.  
  5058. In general it should not be necessary to manipulate directly any of these data
  5059. structures. Functions have been provided in the ARexx Systems Library to
  5060. perform all of the operations required to interface external program to the
  5061. ARexx system. It is therefore recommended that applictions developers avoid
  5062. using any of the internal structures except as provided through the library
  5063. functions.
  5064.  
  5065.                 102
  5066.  
  5067.             APPENDIX A ERROR MESSAGES
  5068.  
  5069. When the ARexx interpeter detects an error in a program,it returns an error
  5070. code to indicate the nature of the problem. Errors are normally handled by
  5071. displaying the error code,the source line number where the error occurred,and a
  5072. brief message explaining the error condition. Unless the SYNTAX interrupt has
  5073. been previously enabled(using the SIGNAL instruction),the program then
  5074. terminates and control returns to the caller. Most syntax and execution errors
  5075. can be trapped by the SYNTAX interrupt,allowing the user to retain control and
  5076. perform whatever special error processing is required. Certain errors are
  5077. generated outside of the context of an ARexx program,and therefore cannot be
  5078. trapped by this mechanism. Refer to chapter 7 for further information on error
  5079. trapping and processing.
  5080.  
  5081. Associated with each error code is a severity level that is reported to the
  5082. calling program as the primary result code. The error code itself is returned
  5083. as the secondary result. The subsequent propagation or reporting of these codes
  5084. is of course dependent on the external(calling)program.
  5085.  
  5086. The following pages list all of the currently-defined error codes,along with
  5087. the associated severity level and message string.
  5088.  
  5089. ERROR: 1 SEVERITY: 5 MESSGE: PROGRAM NOT FOUND
  5090. The named program could not be found,or was not an ARexx program. ARexx
  5091. programs are expected to start with a "/*" sequence. This error is detected by
  5092. the external interface and cannot be trapped by the SYNTAX interrupt.
  5093.  
  5094. ERROR: 2 SEVERITY: 10 MESSAGE: EXECUTION HALTED
  5095. A control-C break or an external half request was received and the program
  5096. terminated. This error will be trapped if the HALT interrupt has been enabled.
  5097.  
  5098. ERROR: 3 SEVERITY: 20 MESSAGE: INSUFFICIENT MEMORY
  5099. The interpreter was unable to allocate enough memory for an operation. Since
  5100. memory space is required for all parsing and execution operations,this error
  5101. cannot usually be trapped by the SYNTAX interrupt.
  5102.  
  5103. ERROR: 4 SEVERITY: 10 MESSAGE: INVALID CHARACTER
  5104. A non-ASCII character was found in the program. Control codes and other non-
  5105. ASCII characters may be used in a program by defining them as hex or binary
  5106. strings. This is a scan phase error and cannot be trapped by the SYNTAX
  5107. interrupt.
  5108.  
  5109. ERROR: 5 SEVERITY: 10 MESSAGE: UNMATCHED QUOTE
  5110. A closing single or double quote was missing. Check that each string is
  5111. properly delimited. This is a scan phase error and cannot be trapped by the
  5112. SYNTAX interrupt.
  5113.  
  5114.                 103
  5115.  
  5116. ERROR: 6 SEVERITY: 10 MESSAGE: UNTERMINATED COMMENT
  5117. The closing "*/" for a comment field was not found. Remember that comments may
  5118. be nested,so each "/*" must be matched by a "*/." This is a scan phase error
  5119. and cannot be trapped by the SYNTAX interrupt.
  5120.  
  5121. ERROR: 7 SEVERITY: 10 MESSAGE: CLAUSE TOO LONG
  5122. A clause was too long for the internal buffer used as temporary storage. The
  5123. source line in question should be broken into smaller parts. This is a scan
  5124. phase error and cannot be trapped by the SYNTAX interrupt.
  5125.  
  5126. ERROR: 8 SEVERITY: 10 MESSAGE: INVALID TOKEN
  5127. An unrecognized lexical token was found,or a clause could not be properly
  5128. classified. This is a scan phase error and cannot be trapped by the SYNTAX
  5129. interrupt.
  5130.  
  5131. ERROR: 9 SEVERITY: 10 MESSAGE: SYMBOL OR STRING TOO LONG
  5132. An attempt was made to create a string longer than the maximum supported by the
  5133. interpreter. The implementation limits for internal structure are given in
  5134. Appendix B.
  5135.  
  5136. ERROR: 10 SEVERITY: 10 MESSAGE: INVALID MESSAGE PACKET
  5137. An invalid action code was found in a message packet sent to the ARexx resident
  5138. process. The packet was returned without being processed. This error is
  5139. detected by the external interface and cannot be trapped by the SYNTAX
  5140. interrupt.
  5141.  
  5142. ERROR: 11 SEVERITY: 10 MESSAGE: COMMAND STRING ERROR
  5143. A command string could not be processed. This error is detected by the external
  5144. interface and cannot be trapped by the SYNTAX interrupt.
  5145.  
  5146. ERROR: 12 SEVERITY: 10 MESSAGE: ERROR RETURN FROM FUNCTION
  5147. An external function returned a non-zero error code. Check that the correct
  5148. parameters were supplied to the function.
  5149.  
  5150. ERROR: 13 SEVERITY: 10 MESSAGE: HOST ENVIRONMENT NOT FOUND
  5151. The message port corresponding to a host address string could not be found.
  5152. Check that the required external host is active.
  5153.  
  5154. ERROR: 14 SEVERITY: 10 MESSAGE: REQUESTED LIBRARY NOT FOUND
  5155. An attempt was made to open a function library included in the Library List,but
  5156. the library could not be opened. Check that the correct name and version of the
  5157. library were specified when the library was added to the resource list.
  5158.  
  5159. ERROR: 15 SEVERITY: 10 MESSGE: FUNCTION NOT FOUND
  5160. A function was called that could not be found in any of the currently
  5161. accessible libraries,and could not be located as an external program. Check
  5162. that the appropriate function libraries have been added to the Libraries List.
  5163.  
  5164.                 104
  5165.  
  5166. ERROR: 16 SEVERITY: 10 MESSAGE: FUNCTION DID NOT RETURN VALUE
  5167. A function was called which failed to return a result string,but did not
  5168. otherwise report an error. Check that the function was programmed correctly,or
  5169. invoke it using the CALL instruction.
  5170.  
  5171. ERROR: 17 SEVERITY: 10 MESSAGE: WRONG NUMBER OF ARGUMENTS
  5172. A call was made to a function which expected more(or fewer)arguments. This
  5173. error will be generated if a Built-In or external function is called with more
  5174. arguments than can be accomodated in the message packet used for external
  5175. communications.
  5176.  
  5177. ERROR: 18 SEVERITY: 10 MESSAGE: INVALID ARGUMENT TO FUNCTION
  5178. An inappropriate argument was supplied to a function,or a required argument was
  5179. missing. Check the parameter requirements specified for the function.
  5180.  
  5181. ERROR: 19 SEVERITY: 10 MESSAGE: INVALID PROCEDURE
  5182. A PROCEDURE instruction was issued in an invalid context. Either no internal
  5183. functions were active,or a PROCEDURE had already been issued in the current
  5184. storage environment.
  5185.  
  5186. ERROR: 20 SEVERITY: 10 MESSAGE: UNEXPECTED THEN OR WHEN
  5187. A WHEN or THEN instruction was executed outside of a valid context. The WHEN
  5188. instruction is valid only within a SELECT range,and THEN must be the next
  5189. instruciton following an IF or WHEN.
  5190.  
  5191. ERROR: 21 SEVERITY: 10 MESSAGE: UNEXPECTED ELSE OR OTHERWISE
  5192. An ELSE or OTHERWISE was found outside of a valid context. The OTHERWISE
  5193. instruction is valid only within a SELECT range. ELSE is valid only following
  5194. the THEN branch of an IF range.
  5195.  
  5196. ERROR: 22 SEVERITY: 10 MESSAGE: UNEXPECTED BREAK,LEAVE,or ITERATE
  5197. The BREAK instruction is valid only within a DO range or inside an INTERPRETed
  5198. string. The LEAVE and ITERATE instuctions are valid only within an iterative DO
  5199. range.
  5200.  
  5201. ERROR: 23 SEVERITY: 10 MESSAGE: INVALID STATEMENT IN SELECT
  5202. A invalid statement was encountered within a SELECT range. Only WHEN,THEN,and
  5203. OTHERWISE statements are valid within a SELECT range,except for the conditional
  5204. statements following THEN or OTHERWISE clauses.
  5205.  
  5206. ERROR: 24 SEVERITY: 10 MESSAGE: MISSING OR MULTIPLE THEN
  5207. An expected THEN clause was not found,or another THEN was found after one had
  5208. already been executed.
  5209.  
  5210. ERROR: 25 SEVERITY: 10 MESSAGE: MISSING OTHERWISE
  5211. None of the WHEN clauses in a SELECT succeeded,but no OTHERWISE clause was
  5212. supplied.
  5213.  
  5214. ERROR: 26 SEVERITY: 10 MESSAGE: MISSING OR UNEXPECTED END
  5215. The program source ended before an END was found for a DO or SELECT instruction
  5216. or an END was encountered outside of a DO or SELECT range.
  5217.  
  5218.                 105
  5219.  
  5220. ERROR: 27 SEVERITY: 10 MESSAGE: SYMBOL MISMATCH
  5221. The symbol specified on an END,ITERATE,or LEAVE instruction did not match the
  5222. index variable for the associated DO range. Check that the active loops have
  5223. been nested properly.
  5224.  
  5225. ERROR: 28 SEVERITY: 10 MESSAGE: INVALID DO SYNTAX
  5226. An invalid DO instruction was executed. An initializer expression must be given
  5227. if a TO or BY expression is specified,and a FOR expression must yield a non-
  5228. negative integer result.
  5229.  
  5230. ERROR: 29 SEVERITY: 10 MESSAGE: INCOMPLETE IF OR SELECT
  5231. An IF or SELECT range ended before all of the required statement were found.
  5232. Check whether the conditional statement following a THEN,ELSE,or OTHERWISE
  5233. clause was omitted.
  5234.  
  5235. ERROR: 30 SEVERITY: 10 MESSAGE: LABEL NOT FOUND
  5236. A label specified by a SIGNAL instruction,or implicitly referenced by an
  5237. enabled interrupt,could not be found in the program source. Labels defined
  5238. dynamically by an INTERPRET instruction or by interactive input are not
  5239. included in the search.
  5240.  
  5241. ERROR: 31 SEVERITY: 10 MESSAGE: SYMBOL EXPECTED
  5242. A non-symbol token was found where only a symbol token is valid. The DROP,END,
  5243. LEAVE,ITERATE,and UPPER instructions may only be followed by a symbol token,and
  5244. will generate this error if anything else is supplied. This message will also
  5245. be issued if a required symbol is missing.
  5246.  
  5247. ERROR: 32 SEVERITY: 10 MESSAGE: SYMBOL OR STRING EXPECTED
  5248. An invalid token was found in a context where only a symbol or string is valid.
  5249.  
  5250. ERROR: 33 SEVERITY: 10 MESSAGE: INVALID KEYWORD
  5251. A symbol token in an instruction clause was identified as a keyword,but was
  5252. invalid in the specific context.
  5253.  
  5254. ERROR: 34 SEVERITY: 10 MESSAGE: REQUIRED KEYWORD MISSING
  5255. An instuction clause required a specific keyword token to be present,but it was
  5256. not supplied. For example,this messge will be issued if a SIGNAL ON instruction
  5257. is not followed by one of the interrupt keywords(e.g.SYNTAX.)
  5258.  
  5259. ERROR: 35 SEVERITY: 10 MESSAGE: EXTRANEOUS CHARACTERS
  5260. A seemingly valid statement was executed,but extra characters were found at the
  5261. end of the clause.
  5262.  
  5263. ERROR: 36 SEVERITY: 10 MESSAGE: KEYWORD CONFLICT
  5264. Two mutually exclusive keywords were included in an instruction clause,or a
  5265. keyword was included twice in the same instruction.
  5266.  
  5267. ERROR: 37 SEVERITY: 10 MESSAGE INVALID TEMPLATE
  5268. The template provided with an ARG,PARSE,or PULL instruction was not properly
  5269. constructed. Refer to Chapter 8 for a description of template structure and
  5270. processing.
  5271.  
  5272.                 106
  5273.  
  5274. ERROR: 38 SEVERITY: 10 MESSAGE: INVALID TRACE REQUEST
  5275. The alphabetic keyword supplied with a TRACE instruction or as the argument to
  5276. the TRACE()Built-In function was not valid. Refer to Chapter 7 for the valid
  5277. TRACE options.
  5278.  
  5279. ERROR: 39 SEVERITY: 10 MESSAGE: UNINITIALIZED VARIABLE
  5280. An attempt was made to use an uninitialized variable while the NOVALUE
  5281. interrupt was enabled.
  5282.  
  5283. ERROR: 40 SEVERITY: 10 MESSAGE: INVALID VARIABLE NAME
  5284. An attempt was made to assign a value to a fixed symbol.
  5285.  
  5286. ERROR: 41 SEVERITY: 10 MESSAGE: INVALID EXPRESSION
  5287. An error was detected during the evaluation an expression. Check that each
  5288. operator has the correct number of operands,and that no extraneous tokens
  5289. appear in the expression. This error will be detected only in expressions that
  5290. are actually evaluated. No checking is performed on expressions in clauses that
  5291. are being skipped.
  5292.  
  5293. ERROR: 42 SEVERITY: 10 MESSAGE: UNBALANCED PARENTHESE
  5294. An expression was found with an unequal number of opening and closing
  5295. parentheses.
  5296.  
  5297. ERROR: 43 SEVERITY: 43 MESSAGE: NESTING LIMIT EXCEEDED
  5298. The number of subexpressions in an expression was greater than the maximum
  5299. allowed. The expression should be simplified by breaking it into two or more
  5300. intermediate expressions.
  5301.  
  5302. ERROR: 44 SEVERITY: 10 MESSAGE: INVALID EXPRESSION RESULT
  5303. The result of an expression was not valid within its context. For example,this
  5304. messge will be issued if an increment or limit expression in a DO instruction
  5305. yields a non-numeric result.
  5306.  
  5307. ERROR: 45 SEVERITY: 10 MESSAGE: EXPRESSION REQUIRED 
  5308. An expression was omitted in a context where one is required. For example,the
  5309. SIGNAL instruction,if not followed by the keywords ON or OFF,must be followed
  5310. by an expression.
  5311.  
  5312. ERROR: 46 SEVERITY: 10 MESSAGE: BOOLEAN VALUE NOT 0 OR 1
  5313. An expression result was expected to yield a boolean result,but evaluated to
  5314. something other than 0 or 1.
  5315.  
  5316. ERROR: 47 SEVERITY: 10 MESSAGE: ARITHMETIC CONVERSION ERROR
  5317. A non-numeric operand was used in a operation requiring numeric operands. This
  5318. message will also be generated by an invalid hex or binary string.
  5319.  
  5320. ERROR: 48 SEVERITY: 10 MESSAGE: INVALID OPERAND
  5321. An operand was not valid for the intended operation. This message will be
  5322. generated if an attempt is made to divide by 0,or if a fractional exponent is
  5323. used in an exponentiation operation.
  5324.  
  5325.                 107
  5326.  
  5327.             APPENDIX B LIMITS AND COMPATIBILITY
  5328.  
  5329. ARexx was designed to adhere closely to the REXX language standard. This
  5330. appendix discusses those areas where ARexx departs from the standard.
  5331.  
  5332. B-1 LIMITS
  5333.  
  5334. Language definitions seldom include predefined limits to the program structures
  5335. that can be created. Only a few such restrictions were imposed in implementing
  5336. ARexx,and most of the internal structure are limited only by the total amount
  5337. of memory available. The current implementation limits are listed below.
  5338.  
  5339. LENGTH OF STRINGS. Strings,symbol names,and value strings are limited to a
  5340. maximum length of 65,535 bytes.
  5341.  
  5342. LENGTH OF CLAUSES. Clauses are limited to a maximum of 800 characters after
  5343. removing comments and multiple blanks.
  5344.  
  5345. NODES IN COMPOUND NAMES. Compound symbol names may include a maximum of 50
  5346. nodes,including the stem.
  5347.  
  5348. ARGUMENTS TO FUNCTIONS. Built-In and external functions are limited to a
  5349. maximum of 15 arguments. There is no limit to the number of arguments that may
  5350. be passed to an internal function.
  5351.  
  5352. SUBEXPRESSION NESTING. The maximum nesting level for subexpressions is 32.
  5353.  
  5354. B-2 COMPATIBILITY
  5355.  
  5356. ARexx departs in a few ways from the language definition. The differences can
  5357. be classified as omissions or extensions,and are described below.
  5358.  
  5359. OMISSIONS. The only significant specification of the language standard omitted
  5360. from this implementation is the arbitrary-precision arithmetic facility.
  5361. Arithmetic operations are limited to about 14 digits of precision,and the FUZZ
  5362. option is not implemented at all. Only the SCIENTIFIC format is used for
  5363. exponential notation. The full numeric capabilities will be provided in a later
  5364. release.
  5365.  
  5366. EXTENSIONS. The following extensions to the language standard have been
  5367. included in this implementation:
  5368.  
  5369. BREAK INSTRUCTION. A new instruction called BREAK has been implemented. It is
  5370. used to exit from the scope of any DO or INTERPRET instruction.
  5371.  
  5372. ECHO INSTRUCTION. The ECHO instruction has been included as a synonym for SAY.
  5373.  
  5374. SHELL INSTRUCTION. The SHELL instructiion has been included as a synonym for
  5375. ADDRESS.
  5376.  
  5377.                 109
  5378.  
  5379. SIGNAL OPTIONS. Several additional SIGNAL keywords have been implemented.
  5380. BREAK_C,BREAK_D,BREAK_E,and BREAK_F will detect and trap the control-C through
  5381. control-F signals passed by AmigaDOS. The IOERR keyword traps errors detected
  5382. by the I/O system.
  5383.  
  5384. STEM SYMBOLS. A stem symbol is valid anywhere that a simple symbol could be
  5385. employed.
  5386.  
  5387. TEMPLATE PROCESSING. Templates have been generalized in several ways. Variable
  5388. symbols may be used as positional tokens if preceded by an operator;the "="
  5389. operator is used to denote an absolute position. Multiple templates can be used
  5390. with all source forms of the PARSE instruction.
  5391.  
  5392.                 110
  5393.  
  5394.             APPENDIX C THE AREXX SYSTEMS LIBRARY
  5395.  
  5396. The ARexx interpreter is supplied as a shared library named rexxsyslib.library
  5397. and should reside in the system LIBS:directory. While many of the library
  5398. routines are highly specific to the interpreter,some of the functions will be
  5399. useful to applications that use ARexx. The library is opened when the ARexx
  5400. resident process is first loaded and will always be available while it remains
  5401. active.
  5402.  
  5403. The system library routines were designed to be called from assembly-language
  5404. programs and,unless otherwise noted,save all registers except for A0/A1 and
  5405. D0/D1. Many routines return values in more than one register to help reduce
  5406. code size. In addition,the routines will set the condition-code register(CCR)
  5407. wherever appropriate. In mode cases the CCR reflects the value returned in D0.
  5408.  
  5409. The library offsets are defined in the file rxslib.i,which should be INDLUDEd
  5410. in the program source code. Calls may be made from "C" programs if suitable
  5411. binding routines are provided when the program is linked. The definitions for
  5412. the constants and data structures used in ARexx are provided as INCLUDE files
  5413. on the program distribution disk. These should be reviewed carefully before
  5414. attempting to use the library functions.
  5415.  
  5416. C-1 FUNCTION GROUPS
  5417. The library functions can be frouped into Conversion,Input/Output,Resource
  5418. Management,and String Manipulation functions.
  5419.  
  5420. DATA CONVERSION. These functions provide many of the common data-conversion
  5421. requirements.
  5422.  
  5423. INPUT/0UTPUT. Two levels of I/O support are provided. The low level functions
  5424. use DOS filehandles directly,while the higher-level functions use linked lists
  5425. of IoBuff structures and support logical file names.
  5426.  
  5427. RESOURCE. These functions allocate,release,or otherwise manage the data
  5428. structures used with ARexx.
  5429.  
  5430. STRING FUNCTIONS. All data in ARexx are managed as strings. These functions
  5431. provide some of the more common string-manipulation operations.
  5432.  
  5433.                 111
  5434.  
  5435.             TABLE C.1 AREXX SYSTEMS LIBRARY FUNCTIONS
  5436.  
  5437. NAME        FUNCTIONAL GROUP    DESCRIPTION
  5438. AddClipNode    Resource        Allocate a Clip node
  5439. ClearMem    Resource        Clear a block of memory
  5440. ClearRexxMsg    Resource        Release argstrings from message
  5441. CloseF        Input/Output        Close a file buffer
  5442. ClosePublicPort    Resource        Close a port resource node
  5443. CmpString    String            Compare string structures for equality
  5444. CreateArgstring    Resource        Create an argstring structure
  5445. CreateDOSPkt    Input/Output        Creata a DOS Standard Packet
  5446. CreateRexxMsg    Resource        Create a message packet
  5447. CurrentEnv    Resource        Get current storage environment
  5448. CVa2i        Conversion        ASCII to integer
  5449. CVc2x        Conversion        Character to Hex or Binary digits
  5450. CVi2a        Conversion        Integer to ASCII
  5451. CVi2arg        Conversion        Integer to ASCII argstring
  5452. CVi2az        Conversion        Integer to ASCII,leading zeroes
  5453. CVs2i        Conversion        String structure to integer
  5454. CVx2c        Conversion        Hex or binary digits to binary
  5455. DeleteArgstring    Resource        Release an argstring structure
  5456. DeleteDOSPkt    Input/Output        Release a DOS Standard Packet
  5457. DeleteRexxMsg    Resource        Release a message packet
  5458. DOSRead        Input/Output        Read from a DOS filehandle
  5459. DOSWrite    Input/Output        Write to a DOS filehandle
  5460. ErrorMsg    Conversion        Get error message from error code
  5461. ExistF        Input/Output        Check whether a DOS file exists
  5462. FillRexxMsg    Resource        Convert and install argstrings
  5463. FindDevice    Input/Output        Locate a DOS device node
  5464. FindRsrcNode    Resource        Locate a resource node
  5465. FreePort    Resource        Close a message port
  5466. FreeSpace    Resource        Release internal memory
  5467. GetSpace    Resource        Allocate internal memory
  5468. InitList    Resource        Initialize a list header
  5469. InitPort    Resource        Initialize a message port
  5470. IsRexxMsg    Resource        Test a message packet
  5471. LengthArgstring    Resource        Get length of argstring
  5472. ListNames    Resource        Copy node names to an argstring
  5473. OpenF        Input/Output        Open a file buffer
  5474. OpenPublicPort    Resource        Allocate and open a port resource node
  5475. QueueF        Input/Output        Queue a line in a file buffer
  5476. ReadF        Input/Output        Read from a file buffer
  5477. ReadStr        Input/Output        Read a string from a file buffer
  5478. RemClipNode    Resource        Release a Clip node
  5479. RemRsrcList    Resource        Release a resource list
  5480. RemRsrcNode    Resource        Release a resource node
  5481.  
  5482.                 112
  5483.  
  5484.             TABLE C.1 LIBRARY FUNCTIONS (cont)
  5485.  
  5486. NAME        FUNCTIONAL GROUP    DESCRIPTION
  5487. SeekF        Input/Output        Reposition a file buffer
  5488. StackF        Input/Output        Stack a line in a file buffer
  5489. StcToken    String            Break out a token
  5490. StrcmpN        String            Compare strings
  5491. StrcpyA        String            Copy a string,converting to ASCII
  5492. StrcpyN        String            Copy a string
  5493. StrCpyU        String            Copy a string,converting to uppercase
  5494. StrflipN    String            Reverse characters in a string
  5495. Strlen        String            Find length of a string
  5496. ToUpper        Conversion        ASCII to uppercase
  5497. WriteF        Input/Output        Write to a file buffer
  5498.  
  5499. C-2 LIBRARY FUNCTIONS
  5500. The following descriptions of the ARexx Systems Library functions are listed
  5501. alphabetically. The required arguments and register assignments are shown in
  5502. parentheses after the function name. Multiple returns are shown in parentheses
  5503. on the left-hand side of the call.
  5504.  
  5505. AddClipNode()-allocate and link a Clip node
  5506. Usage:node=AddClipNode(list,name,length,value)
  5507.     D0        A0   A1    D0     D1
  5508.     A0        
  5509.        (CCR)
  5510.  
  5511. Allocates and links a Clip node into the specified list. Clip nodes are
  5512. resource nodes containing a name and value string,and include an "auto-delete"
  5513. function for simple maintenance. The list argument must point to a properly-
  5514. initialized EXEC list header. The name argument points to a null-terminated
  5515. name string,the value argument is a pointer to a storage area,and the length
  5516. argument is its length in bytes. The returned value is a pointer to the
  5517. allocated node,or 0 if the allocation failed.
  5518.  
  5519. The RemClipNode()function is installed as the "auto-delete" function for each
  5520. node. Clip nodes can be intermixed with other resource nodes in a list and then
  5521. released with a single call to RemRsrcList().
  5522. See Also:RemClipNode(),RemRsrcList(),RemRsrcNode()
  5523.  
  5524. AddRsrcNode()-allocate and link a resource node
  5525. Usage:node=AddRsrcNode(list,name,length)
  5526.     D0        A0   A1    D0
  5527.     A0
  5528.        (CCR)
  5529.  
  5530. Allocates and links a resource node(a RexxRsrc structure)to the specified list.
  5531. The name argument is a pointer to a null-terminated string,a copy of which is
  5532. installed in the node structure. The length argument is the total length for
  5533. the node;this length is saved within the node so that it may be released later.
  5534.  
  5535.                 113
  5536.  
  5537. The returned value is a pointer to the allocated node,or 0 if the allocation
  5538. failed.
  5539. See Also:RemRsrcList(),RemRsrcNode()
  5540.  
  5541. ClearMem()-clear a block of memory
  5542. Usage:ClearMem(address,length)
  5543.         A0       D0
  5544.  
  5545. Clears a block of memory beginning at the given address for the specified
  5546. length in bytes. The address must be word-aligned and the length must be a
  5547. multiple of 4 bytes;all structures allocated by ARexx meet these restrictions.
  5548. Register A0 is preserved.
  5549.  
  5550. ClearRexxMsg()-release argument strings
  5551. Usage:ClearRexxMsg(msgptr,count)
  5552.             A0     D0
  5553.  
  5554. Releases one or more argstrings from a message packet and clears the
  5555. corresponding slots. The count argument specifies the number of argument slots
  5556. to clear,and can be set to less than 16 to reserve some to the slots for
  5557. private use. No action is taken if the slot already contains a zero value.
  5558. See Also:FillRexxMsg()
  5559.  
  5560. CloseF()-close a file buffer
  5561. Usage:boolean=CloseF(IoBuff)
  5562.         D0             A0
  5563.  
  5564. Release the IoBuff structure and closes the associated DOS file. CloseF()is the
  5565. "auto-delete" function for the IoBuff structure,so an entire list of file
  5566. buffers can be closed with a single call to RemRsrcList().
  5567.  
  5568. ClosePublicPort()-close a port resource node 
  5569. Usage:ClosePublicPort(node)
  5570.                        A0
  5571.  
  5572. Unlinks and closes the message port and releases the resource node structure.
  5573. The node must have been allocated by the OpenPublicPort()function.
  5574. See Also:OpenPublicPort()
  5575.  
  5576. CmpString()-compare string structures for equality
  5577. Usage:test=CmpString(ss1,ss2)
  5578.        D0             A0 A1
  5579.       (CCR)
  5580.  
  5581. The arguments ss1 and ss2 must be pointers to ARexx string structures and are
  5582. compared for equality. String structures include the length and hash code of
  5583. the string,so the actual strings are not compared unless the lengths and hash
  5584. codes match. The return value sets the CCR and will be -1(True)if the strings
  5585. match and 0(False)otherwise.
  5586.  
  5587.                 114
  5588.  
  5589. CreateArgstring()-create an argument string structure
  5590. Usage:argstring=CreateArgstring(string,length)
  5591.           D0                      A0     D0
  5592.       A0
  5593.          (CCR)
  5594.  
  5595. Allocates a RexxArg structure and copies the supplied string into it. The
  5596. argstring return is a pointer to the string buffer of the structure,and can be
  5597. treated like an ordinary string pointer. The RexxArg structure stores the
  5598. structure size and string length at negative offsets to the string pointer. The
  5599. string pointer can be set to NULL if only an uninitialized structure is
  5600. required.
  5601. See Also:DeleteArgstring()
  5602.  
  5603. CreateDOSPkt()-allocate and initialize a DOS standard Packet.
  5604. Usage:packet = CreateDOSPkt()
  5605.        D0
  5606.        A0
  5607.       (CCR)
  5608.  
  5609. Allocates a DOS StandardPacket structure and initializes it by interlinking the
  5610. EXEC message and the DOS packet substructures. No replyport is installed in
  5611. either the message or the packet,as these fields are generally filled in just
  5612. before the message is sent.
  5613. See Also:DeleteDOSPkt()
  5614.  
  5615. CreateRexxMsg()-allocate an ARexx message packet
  5616. Usage: msgptr=CreateRexxMsg(replyport,extension,host)
  5617.          D0            A0       A1      D0
  5618.          A0
  5619.         (CCR)
  5620.  
  5621. This function allocates an ARexx message packet from the system free memory
  5622. list. The message packet consists of a standard EXEC message structure extended
  5623. to include space for function arguments,returned results,and internal defaults.
  5624. The replyport argument points to a public or private message port and must be
  5625. supplied,as it is required to return the message packet to the sender. The
  5626. extension and host arguments are pointers to null-terminated strings that
  5627. provide values for the default file extension and the initial host address,
  5628. respectively. Additional override fields in the extended packet except for the
  5629. primary and secondary result fields rm_Result1 and rm_Result2.
  5630. See Also: DeleteRexxMsg()
  5631.  
  5632. CVa2i()-convert from ASCII to integer
  5633. Usage: (digits,value) = CVa2i(buffer)
  5634.           D0     D1             A0
  5635.  
  5636. Converts the buffer of ASCII characters to a signed long integer value. The
  5637. scan proceeds until a non-digit character is found or until an overflow is
  5638. detected. The function returns both the number of digits scanned and the
  5639. converted value.
  5640.  
  5641.                 115
  5642.  
  5643. CVc2x()-convert(unpack)from character string to hex or binary digits.
  5644. Usage: error = CVc2x(outbuff,string,length,mode)
  5645.         D0             A0      A1     D0    D1
  5646.  
  5647. Converts the signed integer value argument to ASCII characters using the
  5648. supplied buffer pointer. The digits argument specifies the maximum number of
  5649. characters that will be copied to the buffer. The returned length is the actual
  5650. number of characters copied. The pointer return is the new buffer pointer.
  5651. See Also: CVi2az()
  5652.  
  5653. CVi2arg()-convert from integer to argstring
  5654. Usage: argstring=CVi2arg(value,digits)
  5655.           D0               D0    D1
  5656.       A0
  5657.      (CCR)
  5658.  
  5659. Converts the signed long integer value argument to ASCII characters,and
  5660. installs them in an argstring(a RexxArg structure). The returned value is an
  5661. argstring pointer or 0 if the allocation failed. The allocated structure can be
  5662. released using DeleteArgstring().
  5663.  
  5664. CVi2az()-convert from integer to ASCII with leading zeroes
  5665. Usage: (length,pointer)=CVi2az(buffer,value,digits)
  5666.           D0      A0            A0     D0    D1
  5667.  
  5668. Converts the signed long integer value argument to ASCII characters in the
  5669. supplied buffer,with leading zeroes to fill out the requested number of digits.
  5670. This function is identical to CVi2a except that leading zeroes are supplied.
  5671. See Also:CVi2a()
  5672.  
  5673. CVs2i()-convert from string structure to integer
  5674. Usage: (error,value)=CVs2i(ss)
  5675.          D0    D1          A0
  5676.  
  5677. The ss argument must be a pointer to a string structure. It is converted to a
  5678. signed long integer value return. The error return code is 47("Arithmetic
  5679. conversion error")if the string is not a valid number.
  5680.  
  5681.                 116
  5682.  
  5683. CVx2c()-convert from hex or binary digits to(packed)string
  5684. Usage:error=CVx2c(outbuff,string,length,mode)
  5685.        D0           A0      A1     D0    D1
  5686.  
  5687. Converts the string argument of hex(0-9,A-F)or binary(0,1)digits to the packed
  5688. binary representation. The mode argument specifies the(hex or binary)conversion
  5689. mode,and must be set to -1 for hex strings or 0 for binary strings. Blank
  5690. characters may be embedded in the string for readability,but only at byte
  5691. boundaries. The error return code is 47 if the string is not a valid hex or
  5692. binary string.
  5693.  
  5694. CurrentEnv()-return the current storage environment
  5695. Usage:envptr=CurrentEnv(rxtptr)
  5696.         D0                A0
  5697.  
  5698. Returns a pointer to the current storage environment associated with an
  5699. executing ARexx program. The rxptr argument is a pointer to the RexxTask
  5700. structure,and may be obtained from the message packet sent to an external
  5701. application.
  5702.  
  5703. DeleteArgstring()-delete(release)an argstring structure
  5704. Usage:DeleteArgstring(argstring)
  5705.                           A0
  5706.  
  5707. Releases an argstring (RexxArg) structure. The RexxArg structure contains the
  5708. total allocated length at a negative offset from the argstring pointer.
  5709. See Also:CreateArgstring()
  5710.  
  5711. DeleteDOSPkt()-release a DOS Standard Packet structure.
  5712. Usage:DeleteDOSPkt(message)
  5713.                       A0
  5714.  
  5715. Releases a DOS StandardPacket structure,typically obtained by a prior call to
  5716. CreateDOSPkt().
  5717. See Also:CreateDOSPkt()
  5718.  
  5719. DeleteRexxMsg()-delete(release)an ARexx message packet.
  5720. Usage:DeleteRexxMsg(packet)
  5721.                       A0
  5722.  
  5723. Release an ARexx message packet to the system free-memory list. The internal
  5724. MN-LENGTH field is used as the total size of the memory block to be released,so
  5725. this function can be used to release any message packet that contains the total
  5726. length in this field. Any embedded argument strings must be released before
  5727. calling DeleteRexxMsg().
  5728. See Also:CreateRexxMsg()
  5729.  
  5730.                 117
  5731.  
  5732. DOSREAD()-read from a DOS file
  5733. Usage:count=DOSRead(filehandle,buffer,length)
  5734.         D0              A0       A1     D0
  5735.        (CCR)
  5736.  
  5737. Reads one or more characters from a DOS filehandle into the supplied buffer.
  5738. The length argument specifies the maximum number of characters that will be
  5739. read. The returned count is the actual number of bytes transferred,or -1 if an
  5740. error occurred.
  5741.  
  5742. DOSWrite()-write to a DOS file
  5743. Usage:count=DOSWrite(filehandle,buffer,length)
  5744.        D0               A0        A1     D0
  5745.       (CCR)
  5746.  
  5747. Writes a buffer of the specified length to a DOS filehandle. The retuned count
  5748. is the actual number of bytes written,or -1 if an error occurred.
  5749.  
  5750. ErrorMsg()-find the message associated with an error code
  5751. Usage:(boolean,ss)=ErrorMsg(code)
  5752.           D0   A0            D0
  5753.  
  5754. Returns the error message(as a pointer to a string structure)associated with
  5755. the specified ARexx error code. The boolean return will be -1 if the supplied
  5756. code was a valid ARexx error code,and 0 otherwise.
  5757.  
  5758. ExistF()-check whether an external file exists
  5759. Usage:boolean=ExistF(filename)
  5760.         D0              A0
  5761.        (CCR)
  5762.  
  5763. Tests whether an external file currently exists by attempting to obtain a read
  5764. lock on the file. The boolean return indicates whether the operation succeeded,
  5765. and the lock is released.
  5766.  
  5767. FillRexxMsg()-convert and install arguments in message packet.
  5768. Usage:boolean=FillRexxMsg(msgptr,count,mask)
  5769.         D0                 A0     D0    D1
  5770.  
  5771. This function can be used to convert and install up to 16 argument strings in a
  5772. RexxMsg structure. The message packet must be allocated and the argument fields
  5773. of interest set to either a pointer to a null-terminated string or an integer
  5774. value. The count argument specifies the number of fields,beginning with ARGO,to
  5775. be converted into argstrings and installed into the argument slot. Bits 0-15 of
  5776. the mask argument specify whether the corresponding argument is a string
  5777. pointer(bit clear)or an integer value(bit set).
  5778.  
  5779.                 118
  5780.  
  5781. The count argument is normally set to the exact number of strings to be passed.
  5782. By setting this count to less than 16,a number of the slots can be reserved for
  5783. private uses.
  5784.  
  5785. The returned value is -1(True)if all of the arguments were successfully
  5786. converted. In the event of an allocation failure,all of the partial results are
  5787. released and a value of 0 is returned.
  5788. See Also:ClearRexxMsg()
  5789.  
  5790. FindDevice()-check whether a DOS device exists.
  5791. Usage:device=FindDevice(devicename,type)
  5792.         D0                  A0      D0
  5793.         A0
  5794.        (CCR)
  5795.  
  5796. Scans the DOS DeviceList for a device node of the specified type matching the
  5797. null-terminated name string. The acceptable values for the type argument are
  5798. the constants DLT_DEVICE,DLT_DIRECTORY,or DLT_VOLUME define in the DOS INCLUDE
  5799. files. Device names are conveted to uppercase before checking for a match. The
  5800. returned value is a pointer to the matched device node,or 0 if the device was
  5801. not found.
  5802.  
  5803. FindRsrcNode()-locate a resource node with the given name.
  5804. Usage:node=FindRsrcNode(list,name,type)
  5805.       D0                 A0   A1   D0
  5806.       A0
  5807.      (CCR)
  5808.  
  5809. Searchs the specified list for the first node of the selected type with the
  5810. given name. The list argument must be a pointer to a properly-initialized EXEC
  5811. list header. The name argument is a pointer to a null-terminated string. If the
  5812. type argument is 0,all nodes are selected;otherwise,the supplied type must
  5813. match the LN_TYPE field of the node. The returned value is a pointer to the
  5814. node or 0 if no matching node was found.
  5815.  
  5816. FreePort()-release resources associated with a message port
  5817. Usage:FreePort(port)
  5818.                 A0
  5819.  
  5820. This function deallocates the signal bit associated with a message port and
  5821. marks the port as "closed." The task calling FreePort()must be the same one
  5822. that initialized the port,since signal bit allocations are specific to a task.
  5823. The memory space associated with the port is not released.
  5824. See Also:InitPort()
  5825.  
  5826. FreeSpace()-releases space to the internal memory allocator.
  5827. Usage:FreeSpace(envptr,block,length)
  5828.                   A0     A1    D0
  5829.  
  5830. Returns a block of memory to the internal allocator,which must have been
  5831. obtained from a call to GetSpace(). The envptr argument is a pointer to the
  5832. base or current storage environment.
  5833. See Also:CurrentEnv(),GetSpace()
  5834.  
  5835.                 119
  5836.  
  5837. GetSpace()-allocate memory using the internal allocator.
  5838. Usage:block=GetSpace(envptr,length)
  5839.        D0              A0     D0
  5840.        A0
  5841.       (CCR)
  5842.  
  5843. Allocates a block of memory using the internal allocator. The memory is
  5844. obtained from an internal pool managed by the interpreter and is returned to
  5845. the operating system when the ARexx program terminates. The envptr argument is
  5846. a pointer to the base or current storage environment for the program.
  5847.  
  5848. The internal allocator must be used to allocate strings for use as values for
  5849. symbols,and is convenient for obtaining small blocks of memory whose lifetime
  5850. will not exceed that of the ARexx program.
  5851. See Also:CurrentEnv(),FreeSpace()
  5852.  
  5853. InitList()-initialize a list header
  5854. Usage:InitList(list)
  5855.                 A0
  5856.  
  5857. Initializes an EXEC list header structure.
  5858.  
  5859. InitPort()-initialize a previously-allocated message port.
  5860. Usage:(signal,port)=InitPort(port,name)
  5861.          D0    A1             A0   A1
  5862.  
  5863. Initializes a message port structure for which memory space has been previously
  5864. allocated,typically as part of a larger structure or as static storage in a
  5865. program. It installs the task ID(of the task calling the function)into the
  5866. MP_SIGTASK field and allocates a signal bit. The name parameter must be a
  5867. pointer to a null-terminated string. The signal return is the signal bit that
  5868. was allocated for the port. In the event that a signal could not be assigned,a
  5869. value of -1 is returned.
  5870.  
  5871. Note that the port is not linked into the system Ports List. If the port is to
  5872. be made public,this can be done after the function returns. The port address is
  5873. returned in the correct register(A1)for a subsequent call to the EXEC function
  5874. AddPort().
  5875. See Also:FreePort()
  5876.  
  5877. IsRexxMsg()-check whether a message came from ARexx.
  5878. Usage:boolean=IsRexxMsg(msgptr)
  5879.          D0               A0
  5880.  
  5881. Tests whether the message packet specified by the msgptr argument came from an
  5882. ARexx program. ARexx marks its messages with a pointer to a static string
  5883. "REXX" in the LN_NAME field. The returned value is either -1(True)if the
  5884. message came from ARexx or 0(False)otherwise.
  5885.  
  5886.                 120
  5887.  
  5888. IsSymbol()-check whether a string is a valid symbol.
  5889. Usage:(code,length)=IsSymbol(string)
  5890.         D0    D1               A0
  5891.  
  5892. Scans the supplied string pointer for ARexx symbol characters. The code return
  5893. is the symbol type if a symbol was found,or 0 if the string did not start with
  5894. a symbol character. The length return is the total length of the symbol.
  5895.  
  5896. ListNames()-build a string of names from a list.
  5897. Usage:argstring=ListNames(list,separator)
  5898.          D0                A0   D0[0:7]
  5899.          A0
  5900.         (CCR)
  5901.  
  5902. Scans the specified list and copies the name strings into an argstring. The
  5903. list argument must be a pointer to an initialized EXEC list header. The
  5904. separator argument is the character,possibly a null,to be placed as a delimiter
  5905. between the node names.
  5906.  
  5907. The list is traversed inside a Forbid()exclusion and so may be used with shared
  5908. or system lists. The returned argstring can be released using DeleteArgstring()
  5909. after the names are no longer needed.
  5910. See Also:DeleteArgstring()
  5911.  
  5912. LockRexxBase()-lock a shared resource.
  5913. Usage:LockRexxBase(resource)
  5914.                       D0
  5915.  
  5916. Secures the specified resource in the ARexx Systems Library base for read
  5917. access. The resource argument is a manifest constant for the required resource,
  5918. or zero to lock the entire structure.
  5919.  
  5920. Note that write access to shared resources is normally mediated by the ARexx
  5921. resident process,which operates at an elevated priority to gain exclusive
  5922. access. Locking a resource should not be attempted from a process operating at
  5923. a priority higher than the resident process.
  5924. See Also:UnlockRexxBase()
  5925.  
  5926. OpenF()-open a file buffer
  5927. Usage:IoBuff=OpenF(list,filename,mode,logical)
  5928.         D0          A0    A1      D0     D1
  5929.         A0
  5930.        (CCR)
  5931.  
  5932. Attempts to open an external file in the specified mode,which should be one of
  5933. the constants RXIO_READ,RXIO_WRITE,or RXIO_APPEND defined in the ARexx INCLUDE
  5934. files. 
  5935.  
  5936.                 121
  5937.  
  5938. If successful,an IoBuff structure is allocated and linked into the specified
  5939. list. The list argument must be a pointer to a properly-initialized EXEC list
  5940. header.
  5941.  
  5942. The optional logical argument is the logical name for the file,and must be
  5943. either a pointer to a null-terminated string or zero(NULL)if a name is not
  5944. required.
  5945. See Also:CloseF()
  5946.  
  5947. OpenPublicPort()-open a public message port
  5948. Usage:node=OpenPublicPort(list,name)
  5949.        D0                  A0   A1
  5950.        A0
  5951.       (CCR)
  5952.  
  5953. Allocates a message port as an "auto-delete" resource node and links it into
  5954. the specified list. The list argument must point to a properly initialized EXEC
  5955. list header. The message port is initialized with the given name and linked
  5956. into the system Ports List.
  5957. See Also:ClosePublicPort()
  5958.  
  5959. QueueF()-queue a line to a file buffer.
  5960. Usage:count-=QueueF(IoBuff,buffer,length)
  5961.         D0            A0     A1     D0
  5962.  
  5963. Queues a buffer of characters in the stream associated with the IoBuff
  5964. structure. The stream must be managed by a DOS handler that supports the
  5965. ACTION_QUEUE packet.
  5966.  
  5967. Queued lines are placed in "first-in,first-out" order and are immediately
  5968. available to be read from the stream. The buffer argument is a pointer to a
  5969. string of characters,and the length specifies the number of characters to be
  5970. queued. The return value is the actual count of characters or -1 if an error
  5971. occurred.
  5972. See Also:StackF()
  5973.  
  5974. ReadF()-read characters from a file buffer
  5975. Usage:count=ReadF(IoBuff,buffer,length)
  5976.        D0           A0     A1     D0
  5977.       (CCR)
  5978.  
  5979. Reads one or more characters from the file specified by the IoBuff pointer. The
  5980. buffer argument is a pointer to a storage area,and the length argument
  5981. specifies the maximum number of characters to be read. The return value is the
  5982. actual number of characters read,or -1 if an error occurred.
  5983.  
  5984. ReadStr()-read a string from a file
  5985. Usage:(count,pointer)=ReadStr(IoBuff,buffer,length)
  5986.         D0     A1               A0     A1     D0
  5987.  
  5988. Reads characters from the file specified by the IoBuff pointer until a
  5989. "newline" character is found. The "newline" is not included in the returned
  5990. string. The return value is the actual number of characters read,or -1 if an
  5991. error occurred.
  5992.  
  5993.                 122
  5994.  
  5995. See Also:ReadF()
  5996.  
  5997. RemClipNode()-unlink and deallocate a list Clip node.
  5998. Usage:RemClipNode(node)
  5999.                    A0
  6000.  
  6001. Unlinks and releases the specified Clip node. The function is the "auto-delete"
  6002. function for Clip nodes,and will be called automatically by RemRsrcNode() or
  6003. RemRsrcList().
  6004. See Also:AddClipNode(),RemRsrcList(),RemRsrcNode()
  6005.  
  6006. RemRsrcList()-unlink and deallocate a list of resource nodes
  6007. Usage:RemRsrcList(list)
  6008.                    A0
  6009.  
  6010. Scans the supplied list and releases any nodes found. The list must consist of
  6011. resource nodes(RexxRsrc structures),which contain information to allow
  6012. automatic cleanup and deletion.
  6013. See Also:RemRsrcNode()
  6014.  
  6015. RemRsrcNode()-unlink and deallocate a resource node
  6016. Usage:RemRsrcNode(node)
  6017.                    A0
  6018.  
  6019. Unlinks and releases the specified resource node,including the name string if
  6020. one is present. If an "auto-delete" function has been specified in the node,it
  6021. is called to perform any required resource deallocation before the node is
  6022. released.
  6023. See Also:RemRsrcList()
  6024.  
  6025. SeekF()-seek to the specified position in a file.
  6026. Usage:position=SeekF(IoBuff,offset,anchor)
  6027.         D0             A0    D0      D1
  6028.  
  6029. Seeks to a new position in the file is specified by the IoBuff pointer. The
  6030. position is given by the offset argument,a byte offset relative to the supplied
  6031. anchor argument. The anchor may specify the beginning(-1),the current position
  6032. (0),or the end of the file(1). The return value is the new position relative to
  6033. the beginning of the file.
  6034.  
  6035. StackF()-stack a line to a file buffer.
  6036. Usage:count=StackF(IoBuff,buffer,length)
  6037.         D0           A0     A1     D0
  6038.  
  6039. Stacks a buffer of characters in the stream associated with the IoBuff
  6040. structure. The buffer argument is a pointer to a string of characters,and the
  6041. length specifies the number of characters to be stacked. The return value is
  6042. the actual count of characters to be stacked. The return value is the actual
  6043. count of characters or -1 if an error occurred.
  6044.             
  6045.                 123
  6046.  
  6047. Stacked lines are placed in "last-in,first-out" order and are immediately
  6048. available to be read from the stream. The stream must be managed by a DOS
  6049. handler that supports the ACTION_STACK packet.
  6050. See Also:QueueF()
  6051.  
  6052. StcToken()-break out the next token from a string
  6053. Usage:(quote,length,scan,token)=StcToken(string)
  6054.         D0     D1    A0   A1               A0
  6055.  
  6056. Scans a null-terminated string to select the next token delimited by "white
  6057. space,"and returns a pointer to the start of the token. The quote return will
  6058. be an ASCII single or double quote if the token was quoted and 0 otherwise;
  6059. white space characters are ignored within quoted strings. The length return is
  6060. the total length of the token,including any quote characters. The scan return
  6061. is advanced beyond the current token to prepare for the next call.
  6062.  
  6063. StrcpyA()-copy a string,converting to ASCII
  6064. Usage:hash=StrcpyA(destination,source,length)
  6065.        D0              A0        A1     D0
  6066.  
  6067. Copies the source string to the destination area,converting the characters to
  6068. ASCII by clearing the high-order bit of each byte. The length of the string
  6069. (which may include embedded nulls)is considered as a 2-byte usingned integer.
  6070. So the string is limited in length to 65,535 bytes. The hash return is the
  6071. internal hash byte for the copied string.
  6072. See Also:StrcpyN(),StrcpyU
  6073.  
  6074. StrcpyN()-copy a string
  6075. Usage:hash=StrcpyN(destination,source,length)
  6076.        D0              A0        A1     D0
  6077.  
  6078. Copies the source string to the destination area. The length of the string
  6079. (which may include embedded nulls)is considered as a 2-byte unsigned integer.
  6080. The hash return is the internal hash byte for the copied string.
  6081. See Also:StrcpyA(),StrcpyU
  6082.  
  6083. StrcpyU()-copy a string,converting to uppercase
  6084. Usage:hash=StrcpyU(destination,source,length)
  6085.        D0               A0       A1     D0
  6086.  
  6087. Copies the source string to the destination area,converting to uppercase
  6088. alphabetics. The length of the string(which may include embedded nulls)is
  6089. considered as a 2-byte unsigned integer. The has return is the internal hash
  6090. byte for the copied string.
  6091. See Also:StrcpyA(),StrcpyN
  6092.  
  6093.                 124
  6094.  
  6095. StrflipN()-reverse the characters in a string
  6096. Usage:StrflipN(string,length)
  6097.                  A0     D0
  6098.  
  6099. Reverses the sequence of characters in a string. The conversion is performed in
  6100. place.
  6101.  
  6102. Strlen()-find the length of a null-terminated string
  6103. Usage:length=Strlen(string)
  6104.         D0            A0
  6105.        (CCR)
  6106.  
  6107. Returns the number of characters in a null-terminated string. Register A0 is
  6108. preserved,and the CCR is set for the returned length.
  6109.  
  6110. StrcmpN()-compare the values of strings
  6111. Usage:test=StrcmpN(string1,string2,length)
  6112.        D0             A0      A1     D0
  6113.       (CCR)
  6114.  
  6115. The string1 and string2 arguments are compared for the specified number of
  6116. characters. The comparison proceeds character-by-character until a difference
  6117. is found or the maximum number of characters have been examined. The returned
  6118. value is -1 if the first string was less,1 if the first string was greater,and
  6119. 0 if the strings match exactly. The CCR register is set for the returned value.
  6120.  
  6121. ToUpper()-translate an ASCII character to uppercase
  6122. Usage:upper=ToUpper(character)
  6123.        D0               D0
  6124.  
  6125. Converts an ASCII character to uppercase. Only register D0 is affected.
  6126.  
  6127. UnlockRexxBase()-unlock a shared resource.
  6128. Usage:UnlockRexxBase(resource)
  6129.                         D0
  6130.  
  6131. Releases the specified resource,or all resources if the argument is zero. Every
  6132. call to LockRexxBase()should be followed eventually by a call to UnlockRexxBase
  6133. ()for the same resource.
  6134. See Also:LockRexxBaseF()
  6135.  
  6136. WriteF()-write characters to a file buffer
  6137. Usage:count=WriteF(IoBuff,buffer,length)
  6138.         D0          A0      A1     D0
  6139.        (CCR)
  6140.  
  6141. Writes a buffer of characters of the specified length to the file associated
  6142. with the IoBuff pointer. The buffer argument is a pointer to a storage area,
  6143.  
  6144.                 125
  6145.  
  6146. and the length argument specifies the number of characters to be written. The
  6147. returned value is the actual number of characters written or -1 if an error
  6148. occurred.
  6149. See Also:CloseF(),OpenF(),ReadF()
  6150.  
  6151.                 126
  6152.  
  6153.             APPENDIX D THE AREXX SUPPORT LIBRARY
  6154.  
  6155. The ARexx language system is distributed with an external function library that
  6156. provides a number of Amiga-specific functions. It is a standard Amiga shared
  6157. library named rexxsupport.library and should reside in the system
  6158. LIBS:directory. Unlike the Systems Library described in the previous
  6159. Appendix,the support library functions are callable from with ARexx programs.
  6160.  
  6161. The support library was designed to supplement the generic Built-In functions
  6162. with functions specific to the Amiga. This library will be expanded in future
  6163. releases,and users are encouraged to submit suggestions for additional
  6164. functions. 
  6165.  
  6166. The Support Library must be added to the global Library List before it can be
  6167. accessed by ARexx programs. This can be done using the Built-In function
  6168. ADDLIB() or by direct communication with the resident process. The library name
  6169. must be specified as rexxsupport.library,the query function offset is -30,and
  6170. the version number is 0. The search priority can be set to 0 or whatever value
  6171. is appropriate.
  6172.  
  6173. ALLOCMEM()
  6174. Usage:ALLOCMEM(length,[attribute])
  6175. Allocates a block of memory of the specified length from the system free-
  6176. memory pool and returns its address as a 4-byte string. The optional attribute
  6177. parameter must be a standard EXEC memory allocation flag,supplied as a 4-byte
  6178. string. The default attribute is for "PUBLIC" memory(not cleared).
  6179.  
  6180. This function should be used whenever memory is allocated for use by external
  6181. programs. It is the user's responsibility to release the memory space when it
  6182. is no longer needed.
  6183. See Also:FREEMEM()
  6184. Example:
  6185.     say c2x(allocmem(1000))    ==>00050000
  6186.  
  6187. CLOSEPORT()
  6188. Usage:CLOSEPORT(name)
  6189. Closes the message port specified by the name argument,which must have been
  6190. allocated by a call to OPENPORT()within the current ARexx program. Any messages
  6191. received but not yet REPLYed are automatically returned with the return code
  6192. set to 10.
  6193. See Also:OPENPORT()
  6194. Example:
  6195.     call closeport myport
  6196.  
  6197.                 127
  6198.  
  6199. FREEMEM()
  6200. Usage:FREEMEM(address,length)
  6201. Releases a block of memory of the given length to the system freelist. The
  6202. address parameter is a four-byte string,typically obtained by a prior call to
  6203. ALLOCMEM(). FREEMEM()cannot be used to release memory allocated using
  6204. GETSPACE(),the ARexx internal memory allocator. The returned value is a boolean
  6205. success flag.
  6206. See Also:ALLOCMEM()
  6207. Example:
  6208.     say freemem('00042000'x,32)    ==>1
  6209.  
  6210. GETARG()
  6211. Usage:GETARG(packet,[n])
  6212. Extracts a command,function name,or argument string from a message packet. The
  6213. packet argument must be a 4-byte address obtained from a prior call to
  6214. GETPKT(). The optional n argument specifies the slot containing the string to
  6215. be extracted,and must be less than or equal to the actual argument count for
  6216. the packet. Commands and functions names are always in slot 0;function packets
  6217. may have argument strings in slots 1-15.
  6218. Examples:
  6219.     command = getarg(packet)
  6220.     function= getarg(packet,0)    /* name string    */
  6221.     arg1    = getarg(packet,1)    /* 1st argumeent*/
  6222.  
  6223. GETPKT()
  6224. Usage:GETPKT(name)
  6225. Checks the message port specified by the name argument to see whether any
  6226. messages are available. The named message port must have been opened by a prior
  6227. call to OPENPORT() within the current ARexx program. The returned value is the
  6228. 4-byte address of the first message packet,or '0000 0000'x if no packets were
  6229. available.
  6230.  
  6231. The function returns immediately whether or not a packet is enqueued at the
  6232. message port. Programs should never be designed to "busy-loop" on a message
  6233. port. If there is no useful work to be done until the next message packet
  6234. arrives,the program should call WAITPKT()and allow other tasks to proceed.
  6235. See Also:WAITPKT()
  6236. Example:
  6237.     packet = getpkt('MyPort')
  6238.  
  6239. OPENPORT()
  6240. Usage:OPENPORT(name)
  6241. Creates a public message port with the given name. The returned value is the
  6242. 4-byte address of the Port Resource strcture or '0000 000'xif the port could
  6243. not be opened or initialized. An initialization failure will occur if another
  6244. port of the same name already exists,or if a signal bit couldn't be allocated.
  6245.  
  6246.                 128
  6247.  
  6248. The message port is allocated as a Port Resource node and is linked into the
  6249. program's global data structure. Ports are automatically closed when the
  6250. program exits,and any pending messages are returned to the sender.
  6251. See Also:CLOSEPORT()
  6252. Example:
  6253.     myport = openport("MyPort")
  6254.  
  6255. REPLY()
  6256. Usage:REPLY(packet,rc)
  6257. Returns a message packet to the sender,with the primary result field set to the
  6258. value given by the rc argument. The secondary result is cleared. The packet
  6259. argument must be supplied as a 4-byte address,and the rc argument must be a
  6260. whole number.
  6261. Example:
  6262.     call reply packet,10        /* error return*/
  6263.  
  6264. SHOWDIR()
  6265. Usage:SHOWDIR(directory,['All' | 'File' | 'Dir'])
  6266. Returns the contents of the specified directory as a string of names separated
  6267. by blanks. The second parameter is an option keyword that selects whether all
  6268. entries,only files,or only subdirectories will be included.
  6269. Example:
  6270.     say showdir("df1:c")        ==>rx ts te hi tco tcc
  6271.  
  6272. SHOWLIST()
  6273. Usage:SHOWLIST[{'D' | 'L' | 'P' | 'R' | 'W' },[name])
  6274. The first argument is an option keyword to select a system list;the options
  6275. currently supported are Devices,Libraries,Ports,Ready,and Waiting. If only the
  6276. first parameter is supplied,the function scans the selected list and returns
  6277. the node names in a string separated by blanks. If the name parameter is
  6278. supplied,the boolean return indicates whether the specified list contains a
  6279. node of that name. The name matching is case-sensitive.
  6280.  
  6281. The list is scanned with task switching forbidden so as to provide an accurate
  6282. snapshot of the list at that time.
  6283. Example:
  6284.     say showlist('P')        ==>REXX MyCon
  6285.     say showlist('P','REXX')    ==>1
  6286.  
  6287.                 129
  6288.  
  6289. STATEF()
  6290. Usage:STATEF(filename)
  6291. Returns a string containing information about an external file. The string is
  6292. formatted as   "{DIR | FILE} length blocks protection comment."
  6293. The length token gives the file length in bytes,and the block token specifies
  6294. the file length in blocks.
  6295. Example:
  6296.     say statef("libs:rexxsupport.library")
  6297.     /* would give "FILE 1880 4 RWED "    */
  6298.  
  6299. WAITPKT()
  6300. Usage:WAITPKT(name)
  6301. Waits for a message to be received at the specified(named)port,which must have
  6302. been opened by a call to OPENPORT() within the current ARexx program. The
  6303. returned boolean value indicates whether a message packet is available at the
  6304. port. Normally the returned value will be 1(True),since the function waits
  6305. until an event occurs at the message port.
  6306.  
  6307. The packet must then be removed by a call to GETPKT(),and should be returned
  6308. eventually using the REPLY()function. Any message packets received but not
  6309. returned when an ARexx program exits are automatically REPLYed with the return
  6310. code set to 10.
  6311. Example:
  6312.     call waitpkt 'MyPort'    /* wait awhile    */
  6313.  
  6314.                 130
  6315.  
  6316.             APPENDIX E DISTRIBUTION FILES
  6317.  
  6318. This appendix lists the directores of the standard ARexx distribution disk. The
  6319. contents of some of the directories may change from time to time,so your disk
  6320. may not show exactly the same files. Most notably,the :rexx directory will
  6321. expand as more program examples are included in it.
  6322.  
  6323. The second section of the Appendix lists the HEADER files that define the
  6324. constants and data structures used with ARexx. All of these files are available
  6325. in the :INCLUDE directory,but are listed here for convenience in studying the
  6326. structures.
  6327.  
  6328. E-1 DIRECTORIES
  6329.  
  6330. The files are listed below as they would be using the system dir command. For
  6331. example,"dir df1:c opt a" would list the contents of the :c directory on disk
  6332. drive 1.
  6333.  
  6334. THE :C DIRECTORY
  6335.  
  6336. This directory contains the command utilities used with ARexx. These files
  6337. should be copied to your system C: directory when you install the program.
  6338.  
  6339.         c(dir)            
  6340.         hi            loadlib
  6341.         rexxmast        rx
  6342.         rxc            rxset
  6343.         tcc            tco
  6344.         te            ts
  6345.  
  6346. THE :INCLUDE DIRECTORY
  6347.  
  6348. This directory has the INCLUDE and HEADER files used for assembly language and
  6349. "C" programming,respectively. These files contain the structure definitions
  6350. necessary to build an interface to ARexx.
  6351.  
  6352.         include(dir)
  6353.         errors.h        rexxio.h
  6354.         rxslib.h        storage.h
  6355.         errors.i        rexxio.i
  6356.         rxslib.i        storage.i
  6357.  
  6358.                 131
  6359.  
  6360. THE :LIBS DIRECTORY
  6361.  
  6362. These are the library files for the language interpreter and the Support
  6363. Library functions. Both files should be copied to your system LIBS:directory
  6364. when you install ARexx.
  6365.  
  6366.         libs(dir)
  6367.         rexxsupport.library    rexxsyslib.library
  6368.  
  6369. THE :REXX DIRECTORY
  6370.  
  6371. The :rexx directory contains example programs to illustrate various features of
  6372. the language. New files will be added from time to time,and users are welcome
  6373. to contribute files to be distributed in this way.
  6374.  
  6375.         rexx(dir)
  6376.         bigif.rexx        break.rexx
  6377.         builtin.rexx        calc.rexx
  6378.         cmdtest.rexx        fact.rexx
  6379.         factw.rexx        haltme.rexx
  6380.         hosttest.rexx        iftest.rexx
  6381.         marquis.rexx        nesttest.rexx
  6382.         paver.rexx        potpourii.rexx
  6383.         rslib.rexx        select.rexx
  6384.         sigtest.rexx        support.rexx
  6385.         test1.rexx        timer.rexx
  6386.  
  6387. THE :TOOLS DIRECTORY
  6388.  
  6389. These files are intended for software developers,and include examples of
  6390. interfacing to ARexx. The file rexxtest is of particular interest;it calls the
  6391. ARexx interpreter directly,and can be run under a debugger to aid with
  6392. developing new function libraries.
  6393.  
  6394.         tools(dir)
  6395.         hosttest        hosttest.asm
  6396.         loadlib.asm        rexxtest
  6397.         rexxtest.asm        rxoffsets.o
  6398.  
  6399. Miscellaneous Files
  6400.  
  6401.         .info            Install-ARexx
  6402.         README            Start-Aexx
  6403.  
  6404.                 132
  6405.  
  6406. E-2 LISTINGS OF HEADER FILES
  6407.  
  6408. This section of the chapter consists of listings of the header files contained
  6409. in the :include directory.
  6410.  
  6411. storage.h
  6412.  
  6413. This is the main header file and contains definitions for all of the important
  6414. data structures used by ARexx.
  6415.  
  6416. /*===rexx/storage.h=================================================
  6417. *
  6418. * Copyright (c) 1986,1987 by William S. Hawes (All Rights Reserved)
  6419. *
  6420. *==================================================================
  6421. * Header file to define ARexx data structures.
  6422. */
  6423.  
  6424. #ifndef REXX_STORAGE_H
  6425. #define REXX_STORAGE_H
  6426.  
  6427. #ifndef EXEC_TYPES_H
  6428. #include "exec/types.h"
  6429. #endif
  6430. #ifndef EXEC_NODES_H
  6431. #include "exec/nodes.h"
  6432. #endif
  6433. #ifndef EXEC_LISTS_H
  6434. #include "exec/lists.h"
  6435. #endif
  6436. #ifndef EXEC_PORTS_H
  6437. #include "exec/ports.h"
  6438. #endif
  6439. #ifndef EXEC_LIBRARIES_H
  6440. #include "exec/libraries.h"
  6441. #endif
  6442.  
  6443. /* The NexxStr structue is used to maintain the internal strings in REXX.
  6444.  * It includes the buffer area for the string and associated attributes.
  6445.  * This is actually a variable-length structure;it is allocated for a
  6446.  * specific length string,and the length is never modified thereafter
  6447.  * (since it's used for recycling).
  6448.  */
  6449.  
  6450.                 133
  6451.  
  6452. storage.h(cont.)
  6453.  
  6454. struct NexxStr{
  6455.     LONG    ns_Ivalue;    /* integer value        */
  6456.     UWORD    ns_Length;    /* length in bytes(excl null)    */
  6457.     UBYTE    ns_Flags;    /* attribute flags        */
  6458.     UBYTE    ns_Hash;    /* hash code            */
  6459.     BYTE    ns_Buff[8];    /* buffer area for strings    */
  6460.     };            /* size: 16 bytes (minimum)    */
  6461.  
  6462. #define NXADDLEN 9        /* offset plus null byte    */
  6463. #define IVALUE(nsPtr) (nsPtr->ns_Ivalue)
  6464.  
  6465. /* String attribute flag bit definitions            */
  6466. #define NSB_KEEP    0    /* permanent string?        */
  6467. #define NSB_STRING    1    /* string form valid?        */
  6468. #define NSB_NOTNUM    2    /* non-numeric?            */
  6469. #define NSB_NUMBER    3    /* a valid number?        */
  6470. #define NSB_BINARY    4    /* integer value saved?        */
  6471. #define NSB_FLOAT    5    /* floating point format?    */
  6472. #define NSB_EXT        6    /* an external string?        */
  6473. #define NSB_SOURCE    7    /* part of the program source?    */
  6474.  
  6475. /* The flag form of the string attributes            */
  6476. #define    NSF_KEEP    (1<< NSB_KEEP  )            */
  6477. #define NSF_STRING    (1<< NSB_STRING)
  6478. #define NSF_NOTNUM    (1<< NSB_NOTNUM)
  6479. #define NSF_NUMBER    (1<< NSB_NUMBER)
  6480. #define NSF_BINARY    (1<< NSB_BINARY)
  6481. #define NSF_FLOAT    (1<< NSB_FLOAT )
  6482. #define NSF_EXT        (1<< NSB_EXT   )
  6483. #define NSF_SOURCE    (1<< NSB_SOURCE)
  6484.  
  6485. * Combinations of flags
  6486. #define    NSF_INTNUM    (NSF_NUMBER | NSF_BINARY | NSF_STRING)
  6487. #define NSF_DPNUM    (NSF_NUMBER | NSF_FLOAT)
  6488. #define NSF_ALPHA    (NSF_NOTNUM | NSF_STRING)
  6489. #define NSF_OWNED    (NSF_SOURCE | NSF_EXT | NSF_KEEP
  6490. #define KEEPSTR        (NSF_STRING | NSF_SOURCE | NSF_NOTNUM)
  6491. #define KEEPNUM        (NSF_STRING | NSF_SOURCE | NSF_NUMBER | NSF_BINARY)
  6492.  
  6493.                 134
  6494.  
  6495. storage.h (cont.)
  6496.  
  6497. /* The RexxArg structure is identical to the NexxStr structure,but
  6498.  * is allocated from system memory rather than from internal storage.
  6499.  * This structure is used for passing arguments to external programs.
  6500.  * It is usually passed as an "argstring",a pointer to the string buffer.
  6501.  */
  6502.  
  6503. struct RexxArg {
  6504.     LONG    ra_Size;    /* total allocated length    */
  6505.     UWORD    ra_Length;    /* length of string        */
  6506.     UBYTE    ra_Flags;    /* attribute flags        */
  6507.     UBYTE    ra_Hash;    /* hash code            */
  6508.     BYTE    ra_Buff[8];    /* buffer area            */
  6509.     };            /* size: 16 bytes (minimum)    */
  6510.  
  6511. /* The RexxMsg structure is used for all communications with Rexx programs.
  6512.  * It is an EXEC message with a parameter block appended.
  6513.  */
  6514. struct RexxMsg{
  6515.     struct Message rm_Node;    /* EXEC message structure    */
  6516.     APTR    rm_TaskBlock;    /* pointer to global structure    */
  6517.     APTR    rm_LibBase;    /* library base            */
  6518.     LONG    rm_Action;    /* command (action) code    */
  6519.     LONG    rm_Result1;    /* primary result (return code)    */
  6520.     LONG    rm_Result2;    /* secondary result        */
  6521.     STRPTR     rm_Args[16];    /* argument block(ARGO-ARG15)    */
  6522.     struct MsgPort *rm_PassPort;  /* forwarding port    */
  6523.     STRPTR    rm_CommAddr;    /* host address (port name)    */
  6524.     STRPTR    rm_FileExt;    /* file extension        */
  6525.     LONG    rm_Stdin;    /* input stream(filehandle)    */
  6526.     LONG    rm_Stdout;    /* output steam(filehandle)    */
  6527.     LONG    rm_avail;    /* future expension        */
  6528.     };            /* size: 128 bytes        */
  6529. /* Field definitions
  6530. #define ARGO(rmp) (rmp->rm_Args[0] /* start of argblock        */
  6531. #define ARG1(rmp) (rmp->rm_Args[1] /* first argument        */
  6532. #define ARG2(rmp) (rmp->rm_Args[2] /* second argument        */
  6533.  
  6534. #define MAXRMARG 15        /* maximum arguments        */
  6535.  
  6536. /* Command (action) codes for message packets            */
  6537. #define RXCOMM    $01000000    /* a command-level invocation    */
  6538. #define    RXFUNC    $02000000    /* a function call        */
  6539. #define RXCLOSE $03000000    /* close the port        */
  6540. #define RXQUERY    $04000000    /* query for information    */
  6541. #define RXADDFH    $07000000    /* add a function host        */
  6542.  
  6543.                 135
  6544.  
  6545. storage.h (cont.)
  6546.  
  6547. #define    RXADDLIB $08000000    /* add a function library    */
  6548. #define RXREMLIB $09000000    /* remove a function library    */
  6549. #define RXADDCON $0A000000    /* add/update a ClipList string */
  6550. #define RXREMCON $0B000000    /* remove a ClipList string    */
  6551. #define RXTCOPN     $0C000000    /* open the trace console    */
  6552. #define RXTCCLS     $0D000000    /* close the trace console    */
  6553.  
  6554. /* Command modifier flag bits                    */
  6555. #define    RXFB_NOIO    16    /* suppress I/O inheritance?    */
  6556. #define    RXFB_RESULT    17    /* result string expected?    */
  6557. #define    RXFB_STRING    18    /* program is a "string file"?    */
  6558. #define    RXFB_TOKEN    19    /* tokenize the command line?    */
  6559. #define    RXFB_NONRET    20    /* a "no-return" message?    */
  6560.  
  6561. /* Modifier flags                        */
  6562. #define    RXFF_RESULT    (1<< RSFB_RESULT)
  6563. #define    RXFF_STRING    (1<< RXFB_STRING)
  6564. #define    RXFF_TOKEN    (1<< RXFB_TOKEN )
  6565. #define    RXFF_NONRET    (1<< RXFB_NONRET)
  6566. #define    RXCODEMASK    $FF000000
  6567. #define RXARGMASK    $0000000F
  6568.  
  6569. /* The RexxRsrc structure is used to manage global resources.
  6570.  * The name string for each node is created as a RexxArg structure,
  6571.  * and the total size of the node is saved in the "rr_Size" field.
  6572.  * Functions are provided to allocate and release resource nodes.
  6573.  * If special deletion operations are required,an offset and base can
  6574.  * be provided in "rr_Func" and "rr_Base",respectively. This function
  6575.  * will be called with the base in register A6 and the node in A0.
  6576. */
  6577. struct RexxRsrc {
  6578.     struct Node rr_Node;
  6579.     WORD    rr_Func;    /* a "auto-delete" offset    */
  6580.     APTR    rr_Base;    /* "auto-delete" base        */
  6581.     LONG    rr_Size;    /* total size of node        */
  6582.     LONG    rr_Arg1;    /* available ...        */
  6583.     LONG    rr_Arg2;    /* available ...        */
  6584.     };            /* size: 32 bytes        */
  6585. /* Resource node types                        */
  6586. #define    RRT_ANY        0    /* any node type ...        */
  6587. #define    RRT_LIB        1    /* a function library        */
  6588. #define    RRT_PORT    2    /* a public port        */
  6589. #define    RRT_FILE    3    /* a file IoBuff        */
  6590. #define    RRT_HOST    4    /* a function host        */
  6591. #define    RRT_CLIP    5    /* a Clip List node        */
  6592.  
  6593.                 136
  6594.  
  6595. storage.h (cont.)
  6596.  
  6597. /* The RexxTask structure holds the fields used by REXX to communicate with
  6598.  * external processes,including the client task. It includes the global
  6599.  * data structure(and the base environm
  6600.